详解Docker之Compose服务编排

2020-06-17 06:53:28易采站长站整理

将会在

/etc/hosts
创建记录:


162.242.195.82 somehost
50.31.209.229 otherhost

extends

继承自当前yml文件或者其它文件中定义的服务,可以选择性的覆盖原有配置。


extends:
file: common.yml
service: webapp

service必须有,file可选。service是需要继承的服务,例如web、database。

net

设置网络模式。同docker的

--net
参数。


net: "bridge"
net: "none"
net: "container:[name or id]"
net: "host"

dns

自定义dns服务器。


dns: 8.8.8.8
dns:
- 8.8.8.8
- 9.9.9.9

cpu_shares, cpu_quota, cpuset, domainname, hostname, ipc, mac_address, mem_limit, memswap_limit, privileged, read_only, restart, shm_size, stdin_open, tty, user, working_dir

这些命令都是单个值,含义请参考docker run。


cpu_shares: 73
cpu_quota: 50000
cpuset: 0,1

user: postgresql
working_dir: /code

domainname: foo.com
hostname: foo
ipc: host
mac_address: 02:42:ac:11:65:43

mem_limit: 1000000000
mem_limit: 128M
memswap_limit: 2000000000
privileged: true

restart: always

read_only: true
shm_size: 64M
stdin_open: true
tty: true

命令行参考


$ docker-compose
Define and run multi-container applications with Docker.

Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...] docker-compose -h|--help

Options:
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
-p, --project-name NAME Specify an alternate project name (default: directory name)
--verbose Show more output
-v, --version Print version and exit
-H, --host HOST Daemon socket to connect to

--tls Use TLS; implied by --tlsverify
--tlscacert CA_PATH Trust certs signed only by this CA
--tlscert CLIENT_CERT_PATH Path to TLS certificate file
--tlskey TLS_KEY_PATH Path to TLS key file
--tlsverify Use TLS and verify the remote
--skip-hostname-check Don't check the daemon's hostname against the name specified
in the client certificate (for example if your docker host
is an IP address)

Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
config Validate and view the compose file
create Create services
down Stop and remove containers, networks, images, and volumes