一 简介
docker-compose.yml是Compose的默认模板文件。该文件有多种写法,例如Version 1 file format、Version 2 file format、Version 2.1 file format、Version 3 file format等。其中,Version 1 file format将逐步不再使用,Version 2.x及Version 3.x基本兼容,是未来的趋势。考虑到目前业界的使用情况,本篇讨论Version 2 file format下的常用命令。
二 命令说明
1 build
配置构建时的选项,Compose会利用它自动构建镜像。build的值可以是一个路径,例如:
build: ./dir
也可以是一个对象,用于指定Dockerfile和参数,例如:
build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
buildno: 1
2 command
覆盖容器启动后默认执行命令:
command: bundle exec thin -p 3000
也可以是一个list,类似于Dockerfile中的CMD指令,格式如下:
<