十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
定義配置文件中的部分(如構(gòu)建,部署,依賴,網(wǎng)絡(luò)等)的頂級鍵與支持它們作為子主題的選項一起列出。這映射到Compose文件的<key>:<option>:<value>
縮進結(jié)構(gòu)
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比鹿城網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式鹿城網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋鹿城地區(qū)。費用合理售后完善,十余年實體公司更值得信賴。
Compose文件是定義services,networks和volumes的YAML文件。 Compose文件的默認路徑是./docker-compose.yml。
服務(wù)定義包含應(yīng)用于為該服務(wù)啟動的每個容器的配置. 類似:
docker container create
docker network create
docker volume create
version: "3.7" #版本
services: #服務(wù)
nginx: #服務(wù)名稱
build: ./dir #指定構(gòu)建目錄
image: nginx:tag #指定基礎(chǔ)鏡像
build:
context: ./dir
build:
context: .
dockerfile: Dockerfile-alternate
ARG buildno
ARG gitcommithash
build:
context: .
args:
buildno: 1
注意: 在Dockerfile中,如果在FROM指令之前指定ARG,則在FROM下的構(gòu)建指令中不能使用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
分區(qū)的大小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>
中。源名稱和目標安裝點都設(shè)置為配置名稱. 支持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
: 要在服務(wù)的任務(wù)容器中裝入的文件的路徑和名稱。默認為:/<source>
uid和gid
: 在服務(wù)的任務(wù)容器中擁有已裝入的配置文件的數(shù)字UID或GID.默認為0.mode
: 以八進制表示法在服務(wù)的任務(wù)容器中裝入的文件的權(quán)限。默認值為0444.配置無法寫入,因為它們安裝在臨時文件系統(tǒng)中,因此如果設(shè)置了可寫位,則會將其忽略??梢栽O(shè)置可執(zhí)行位。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
: 以依賴順序啟動服務(wù).docker-compose up SERVICE
: 自動包含SERVICE的依賴項.docker-compose stop
: 按依賴順序停止服務(wù).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為服務(wù)分配虛擬IP(VIP),作為客戶端到達網(wǎng)絡(luò)服務(wù)的前端。 Docker在客戶端和服務(wù)的可用工作節(jié)點之間路由請求,而無需客戶端知道有多少節(jié)點參與服務(wù)或其IP地址或端口。endpoint_mode: DNSrr
: DNS循環(huán)(DNSRR)服務(wù)發(fā)現(xiàn)不使用單個虛擬IP。 Docker為服務(wù)設(shè)置DNS條目,以便服務(wù)名稱的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
:一次更新的容器數(shù)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