1:参数详解
service: 定义服务
web: 二级标签,服务名称,用户自己定义
image: 指定服务镜像的名称或ID,如果本地镜像不存在,Compose将会尝试拉取这个镜像
格式: image: redis
image: ubuntu:14.04
image: tutum/influxdb
image: example-registry.com:4000/postgresql
image: a4bc65fd
build: 服务除了可以基于指定的镜像,还可以基于一份 Dockerfile,
在使用 up 启动之时执行构建任务,这个构建标签就是 build,
它可以指定 Dockerfile 所在文件夹的路径。Compose 将会利用它自动构建这个镜像,
然后使用这个镜像启动服务容器。
格式: build: /path/to/build/dir
build: ./dir 相对路径
build: 设定上下文根目录,然后以该目录为准指定 Dockerfile
context: ../
dockerfile: path/of/Dockerfile
###ARG:是在build的时候存在的,可以在Dockerfile中当做变量来使用,ARG是允许空值的,构建成功之后会消失
###ENV:是容器构建好之后的变量,不能再Dockerfile中当参数使用,不允许空值
build:
context: . context:上下文
args:
buildno: 1
password: secret
build:
context: .
args:
- buildno=1
- demo 空值
- password=secret
ports: 映射端口的标签
格式:
ports:
- "3000"
- "8000:8000"
###YAML 的布尔值(true, false, yes, no, on, off)
###必须要使用引号引起来(单引号、双引号均可),否则会当成字符串解析。
command: 使用 command 可以覆盖容器启动后默认执行的命令。
格式:
command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000] 这是dockerfile中的文件格式
container_name: 虽然可以自定义项目名称、服务名称,但是如果你想完全控制容器的命名,
可以使用这个标签指定
格式:
container_name: app
depends_on: 解决容器启动先后顺序问题,避免了容器依赖因启动顺序不同而造成退出错误
格式:
depends_on:
- db 先启动数据库在启动redis
- redis
https://blog.csdn.net/liguangxianbin/article/details/79492866