docker-compose command多条指令
参考:https://juejin.cn/s/docker-compose%20%E8%A6%86%E7%9B%96cmd
参考:https://blog.51cto.com/u_15859002/5821804
参考:docker 容器在 docker-compose.yml 中 command 执行多个指令,在启动容器之前执行命令
形式1:
version: '3'
services:
web:
image: nginx:alpine
command: ["nginx", "-g", "daemon off;"]
在上面的示例中,我们将命令指定为nginx -g daemon off;,这将覆盖镜像中的默认CMD命令。
形式2:
version: '2'
services:
prj1:
build:
context: .
dockerfile: Dockerfile.prj1
environment:
SERVER_LISTEN_URI: "tcp://0.0.0.0:9000"
#执行多条指令
command: /bin/bash -c "cp /app/dtest/config.default.yml /app/config.yml && python -u /app/dtest/tcc.py"
#目录映射
volumes:
- ..:/app
- ./tmp:/var/tmp
ports:
- "9000:9000"
links:
- redis
形式三:
version: '3.7'
services:
web:
image: nginx
ports:
- 8080:80
command:
- /bin/bash
- -c
- |
nginx -t
nginx -g "daemon off;"