docker-compose -h
打印出docker-compose所有支持的参数flag
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
--log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
--no-ansi Do not print ANSI control characters
-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
--project-directory PATH Specify an alternate working directory
(default: the path of the Compose file)
--compatibility If set, Compose will attempt to convert keys
in v3 files to their non-Swarm equivalent
--env-file PATH Specify an alternate environment file
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
events Receive real time events from containers
exec Execute a command in a running container
help Get help on a command
images List images
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pull service images
push Push service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show the Docker-Compose version information
如无指定,则默认寻找当前目录下的docker-compose.yml以及docker-compose.override.yml,如果两个都存在则全部读取
如无指定,则默认为目录名称。规则如下
目录名称_服务名称_编号 其中,如果有.字符的话,则去除掉 ,如zabbix-docker-44_mysql-server_1
version: '3.5'
services:
appsrv:
image: alpine
entrypoint: ping "${HOST}"
从文件中可以看到有个HOST这个变量,具体值,我们通过文件或命令行的方式进行传递
通过文件.env方式,进行参数传递
.env 文件内容
HOST=127.0.0.1
运行结果
$ docker-compose up
Starting demo_appsrv_1 ... done
Attaching to demo_appsrv_1
appsrv_1 | PING 127.0.0.1 (127.0.0.1): 56 data bytes
appsrv_1 | 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.061 ms
appsrv_1 | 64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.147 ms
^CGracefully stopping... (press Ctrl+C again to force)
Stopping demo_appsrv_1 ...
Killing demo_appsrv_1 ... done
version: "3.7"
services:
web:
build: .
depends_on:
- db
- redis
redis:
image: redis
db:
image: postgres
$ docker-compose ps
Name Command State Ports
---------------------------------------------
demo_appsrv_1 ping database Up
demo_db_1 sleep 10 Up
$ docker history alpine
IMAGE CREATED CREATED BY SIZE COMMENT
cc0abc535e36 5 weeks ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ADD file:36fdc8cb08228a870… 5.59MB
从history来看,默认的alpine的容器启动的第一条命令为/bin/sh
version: '3.5'
services:
appsrv:
image: "${IMAGE}"
command: ["env"]
depends_on:
- db
links:
- db:database
db:
image: alpine
entrypoint: sleep 10
这里使用command将容器启动的第一条命令修改为env
结果如下:
$ docker-compose up
Starting demo_db_1 ... done
Starting demo_appsrv_1 ... done
Attaching to demo_db_1, demo_appsrv_1
appsrv_1 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
appsrv_1 | HOSTNAME=0ddeb85e3941
appsrv_1 | HOME=/root
demo_appsrv_1 exited with code 0