您好,登錄后才能下訂單哦!
定義配置文件中的部分(如構建,部署,依賴,網絡等)的頂級鍵與支持它們作為子主題的選項一起列出。這映射到Compose文件的<key>:<option>:<value>
縮進結構
Compose文件是定義services,networks和volumes的YAML文件。 Compose文件的默認路徑是./docker-compose.yml。
服務定義包含應用于為該服務啟動的每個容器的配置. 類似:
docker container create
docker network create
docker volume create
version: "3.7" #版本
services: #服務
nginx: #服務名稱
build: ./dir #指定構建目錄
image: nginx:tag #指定基礎鏡像
build:
context: ./dir
build:
context: .
dockerfile: Dockerfile-alternate
ARG buildno
ARG gitcommithash
build:
context: .
args:
buildno: 1
注意: 在Dockerfile中,如果在FROM指令之前指定ARG,則在FROM下的構建指令中不能使用ARG。
YAML布爾值(true,false,yes,no,on,off)必須用引號括起來,以便解析器將它們解釋為字符串。
build:
context: .
cache_from:
- alpine:latest
- corp/web_app:3.14
build:
context: .
labels:
com.example.description: "Accounting webapp"
/dev/shm
分區的大小build:
context: .
shm_size: '2gb'
build:
context: .
target: prod
cap_add:
- ALL
cap_drop:
- NET_ADMIN
- SYS_ADMIN
cgroup_parent: m-executor-abcd
command: ["bundle", "exec", "thin", "-p", "3000"]
/ <config_name>
中。源名稱和目標安裝點都設置為配置名稱. 支持3.3版本以上.version: "3.7"
services:
redis:
image: redis:latest
deploy:
replicas: 1
configs:
- my_config
- my_other_config
configs:
my_config:
file: ./my_config.txt
my_other_config:
external: true
source
: Docker中存在的配置名稱target
: 要在服務的任務容器中裝入的文件的路徑和名稱。默認為:/<source>
uid和gid
: 在服務的任務容器中擁有已裝入的配置文件的數字UID或GID.默認為0.mode
: 以八進制表示法在服務的任務容器中裝入的文件的權限。默認值為0444.配置無法寫入,因為它們安裝在臨時文件系統中,因此如果設置了可寫位,則會將其忽略。可以設置可執行位。version: "3.7"
services:
redis:
image: redis:latest
deploy:
replicas: 1
configs:
- source: my_config
target: /redis_config
uid: '103'
gid: '103'
mode: 0440
configs:
my_config:
file: ./my_config.txt
my_other_config:
external: true
container_name: nginx-test
version: "3.8"
services:
myservice:
image: myimage:latest
credential_spec:
config: my_credential_spec
configs:
my_credentials_spec:
file: ./my-credential-spec.json|
docker-compose up
: 以依賴順序啟動服務.docker-compose up SERVICE
: 自動包含SERVICE的依賴項.docker-compose stop
: 按依賴順序停止服務.version: "3.7"
services:
web:
build: .
depends_on:
- db
- redis
redis:
image: redis
db:
image: postgres
version: "3.7"
services:
redis:
image: redis:alpine
deploy:
replicas: 6
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
endpoint_mode: vip
: Docker為服務分配虛擬IP(VIP),作為客戶端到達網絡服務的前端。 Docker在客戶端和服務的可用工作節點之間路由請求,而無需客戶端知道有多少節點參與服務或其IP地址或端口。endpoint_mode: dnsrr
: DNS循環(DNSRR)服務發現不使用單個虛擬IP。 Docker為服務設置DNS條目,以便服務名稱的DNS查詢返回IP地址列表,客戶端直接連接到其中一個。version: "3.7"
services:
wordpress:
image: wordpress
ports:
- "8080:80"
networks:
- overlay
deploy:
mode: replicated
replicas: 2
endpoint_mode: vip
mysql:
image: mysql
volumes:
- db-data:/var/lib/mysql/data
networks:
- overlay
deploy:
mode: replicated
replicas: 2
endpoint_mode: dnsrr
volumes:
db-data:
networks:
overlay:
version: "3.7"
services:
web:
image: web
deploy:
labels:
com.example.description: "This label will appear on the web service"
version: "3.7"
services:
worker:
image: dockersamples/examplevotingapp_worker
deploy:
mode: global
version: "3.7"
services:
db:
image: postgres
deploy:
placement:
constraints:
- node.role == manager
- engine.labels.operatingsystem == ubuntu 14.04
preferences:
- spread: node.labels.zone
version: "3.7"
services:
worker:
image: dockersamples/examplevotingapp_worker
networks:
- frontend
- backend
deploy:
mode: replicated
replicas: 6
version: "3.7"
services:
redis:
image: redis:alpine
deploy:
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
none
,on-failure
,anyversion: "3.7"
services:
redis:
image: redis:alpine
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
continue或者pause
ns|us|ms|s|m|h
parallelism
:一次更新的容器數delay
: 更新一組容器之間的等待時間.continue,rollback,pause
.默認pause.(ns|us|ms|s|m|h)
version: "3.7"
services:
vote:
image: dockersamples/examplevotingapp_vote:before
depends_on:
- redis
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
order: stop-first
dns:
- 8.8.8.8
- 9.9.9.9
dns_search:
- dc1.example.com
- dc2.example.com
entrypoint: /code/entrypoint.sh
env_file:
- ./common.env
- ./apps/web.env
- /opt/secrets.env
VAR = VAL
格式。以#開頭的行被視為注釋并被忽略。空行也被忽略。environment:
RACK_ENV: development
SHOW: 'true'
SESSION_SECRET:
expose:
- "3000"
- "8000"
external_links:
- redis_1
- project_db_1:mysql
- project_db_1:postgresql
extra_hosts:
- "somehost:162.242.195.82"
- "otherhost:50.31.209.229"
162.242.195.82 somehost
50.31.209.229 otherhost
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
test: ["CMD", "curl", "-f", "http://localhost"]
test: ["CMD-SHELL", "curl -f http://localhost || exit 1"]
test: curl -f https://localhost || exit 1
healthcheck:
disable: true
version: "3.7"
services:
web:
image: alpine:latest
init: true
web:
links:
- db
- db:database
- redis
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。