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