Compose file version 3 reference
Compose ํ์ผ ๊ตฌ์กฐ์ ์์
๋ค์์ ํฌํ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฐ๋จํ ์ปดํฌ์ฆ ํ์ผ ์์์ด๋ค.
version: "3.9"
services:
redis:
image: redis:alpine
ports:
- "6379"
networks:
- frontend
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
db:
image: postgres:9.4
volumes:
- db-data:/var/lib/postgresql/data
networks:
- backend
deploy:
placement:
max_replicas_per_node: 1
constraints:
- "node.role==manager"
vote:
image: dockersamples/examplevotingapp_vote:before
ports:
- "5000:80"
networks:
- frontend
depends_on:
- redis
deploy:
replicas: 2
update_config:
parallelism: 2
restart_policy:
condition: on-failure
result:
image: dockersamples/examplevotingapp_result:before
ports:
- "5001:80"
networks:
- backend
depends_on:
- db
deploy:
replicas: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
worker:
image: dockersamples/examplevotingapp_worker
networks:
- frontend
- backend
deploy:
mode: replicated
replicas: 1
labels: [APP=VOTING]
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
placement:
constraints:
- "node.role==manager"
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
stop_grace_period: 1m30s
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints:
- "node.role==manager"
networks:
frontend:
backend:
volumes:
db-data:
์ปดํฌ์ฆ ํ์ผ์ด๋ service
network
๊ทธ๋ฆฌ๊ณ volume
์ ์ ์ํ๋ ์ผ๋ฏํ์ผ์ด๋ค. ์ปดํฌ์ฆ ํ์ผ์ ๊ธฐ๋ณธ ๊ฒฝ๋ก๋ ./docker-compose.yml
์ด๋ค.
.yml
์ด๋.yaml
๋ ๋ค ์ฌ์ฉ ๊ฐ๋ฅ
service ์ ์๋ ๊ฐ๊ฐ์ ์ปจํ ์ด๋์ ์ ์ฉ๋๋ configuration์ ํฌํจํ๊ณ ์๋ค.
configuration์ ์์: docker run
์ ๋งค๊ฐ๋ณ์๊ฐ์ ๊ฒ์ ๋๊ฒจ์ฃผ๋ ์ผ ๊ฐ์ ๊ฒ๋ค
์ ์ง๊ธ๋ถํฐ list of all configuration option์ ์๊ฐํด๋๋ฆด๊ฒ์โผ๏ธ
build time์ ์ ์ฉ๋๋ configuration option๋ค์ด๋ค.
build
๋
buildํ๋ ค๋ context์ ๊ฒฝ๋ก๋ฅผ ์ค์ ํ๋ String
build: ./dir
๋๋ object์ด๊ธฐ๋ ํ๋ค. ๋ค์์ context, dockerfile, args๋ผ๋ ํ๋กํผํฐ๋ฅผ ๊ฐ์ง๋ ์ค๋ธ์ ํธ์ธ ๊ฒฝ์ฐ์ด๋ค.
build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
buildno: 1
๋ง์ฝ ์ฐ๋ฆฌ๊ฐ image
๋ผ๋ configuration option์ ์ถ๊ฐํด์ build
ํ์ ์์ฑ๋๋ ์ด๋ฏธ์ง์ ์ด๋ฆ๊ณผ ํ๊ทธ๋ฅผ ์ง์ ํด์ค ์ ์๋ค.
build: ./dir
image: webapp:tag # ์ด๋ฏธ์ง์ด๋ฆ์ด webapp ์ด๊ณ ํ๊ทธ๊ฐ tag๋ก ๋น๋๋๋ค.
์ปจํ์คํธ๋ Dockerfile์ ํฌํจํ๋ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ก ๋๋ git repo์ url์ด๋ค.
์๋๊ฒฝ๋ก๊ฐ ๊ฐ์ผ๋ก ์ฃผ์ด์ก์๋, ์ด๊ฑด compose file์ ๊ธฐ์ค์ผ๋กํ ๊ฒฝ๋ก๋ก ํด์๋๋ค. ์ด ๋๋ ํ ๋ฆฌ๋ Docker daemon์ผ๋ก ๋ณด๋ด์ง๋ค.
build:
context: ./dir
Dockerfile์ ๋์ฒดํ๋ ํ์ผ์ ์ง์ ํด์ค๋ค.
build ๊ณผ์ ์์๋ง ์ ๊ทผ ๊ฐ๋ฅํ ํ๊ฒฝ๋ณ์์ธ build argument๋ฅผ ์ถ๊ฐํ๋ค.
์ผ๋ฐ ๋์ปค ํ์ผ์์๋ ๋ค์๊ณผ ๊ฐ์ ๋ฌธ๋ฒ์ ๊ฐ์ง๊ณ ์์๋ค.
# syntax=docker/dockerfile:1
ARG buildno
ARG gitcommithash
RUN echo "Build number: $buildno"
RUN echo "Based on commit: $gitcommithash"
args๋ ๋ง์ฐฌ๊ฐ์ง๋ก build์ ํ๋กํผํฐ๋ก ์ค๊ฒ ๋๋ค. ์ด๋ฐ์์ผ๋ก ํ ์ ์๋ค.
build:
context: .
args:
buildno: 1
gitcommithas: cdc3b19
array๋ก ํํํ ์๋ ์๋ค.
build:
context: .
args:
- buildno=1
- gitcommithash=cdc3b19
build argument๋ค์ ๊ทธ ๊ฐ์ ์๋ตํ ์๋ ์๋๋ฐ, ๊ทธ๋ ๊ฒ ๋๋ฉด ๋น๋ ์ ์ธ์๊ฐ์ ์ด์ ์ Compose๊ฐ ์คํํ๋ ํ๊ฒฝ์ ๊ฐ์ด ๋๋ค.
๋น๋ํ๋ ๋์์ RUN ๊ธฐ๊ณ์ด๊ฐ ์ฐ๊ฒฐ๋ ๋คํธ์ํฌ ์ปจํ ์ด๋๋ฅผ ์ค์ ํ๋ค. (๋ญ์๋ฆฌ์ง)
build:
context: .
network: host
build:
context: .
network: custom_network_1
๋ง์ฝ ๋น๋ ํ๋๋์ ๋คํธ์ํฌ๊ฐ ๋ถ๊ฐ๋ฅํ๊ฒ ํ๊ณ ์ถ์ผ๋ฉด ๊ฐ์ผ๋ก none
์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
default command๋ฅผ ๋ฎ์ด์ด๋ค.
command: bundle exec thin -p 3000
dockerfile์์์ฒ๋ผ ๋ฆฌ์คํธ๋ก ํํํ ์๋ ์๋ค.
command: ["bundle", "exec", "thin", "-p", "3000"]
configํ์ผ์ ์ด๋ฆ์ ์ง๋ ์งง์ ๋ฌธ๋ฒ์ด๋ค. ์ด grants(์ด๋)๋ ์ปจํ ์ด๋๊ฐ ๊ฐ๋ฐ์์ config ํ์ผ์ ์ ๊ทผํ ์ ์๊ฒ ํ๊ณ , ์ปจํ ์ด๋์ ์ฐ๋ฆฌ๊ฐ ์ค์ ํ ์ด๋ฆ์ผ๋ก ์ ์ฅ๋๊ฒ ํ๋ค. ? source name๊ณผ destination mountpoint ๋ ๋ชจ๋ config name์ผ๋ก ์ค์ ๋๋ค. ?
version: "3.9"
services:
redis:
image: redis:latest
deploy:
replicas: 1
configs: # ์ฌ์ฉํ๋ configuration file๋ค์ ์ด๋ฆ
- my_config
- my_other_config
configs: # ์ฌ๊ธฐ์ ์ ์ํจ.
my_config:
file: ./my_config.txt
my_other_config:
external: true
๊ธฐ๋ณธ๊ฐ์ผ๋ก ์คํ๋์ง ์๋๋ก ์ปจํ ์ด๋์ ์ด๋ฆ์ ์ปค์คํ ์ผ๋ก ์ค์ ํ ์ ์๋ค.
container_name: my-web-container
๋์ปค ์ปจํ ์ด๋๋ ๋ฐ๋์ uniqueํด์ผํ๊ธฐ ๋๋ฌธ์ ๋ง์ฝ ์ปจํ ์ด๋ ์ด๋ฆ์ ์ค์ ํ์ ๊ฒฝ์ฐ์๋ ํด๋น ์ด๋ฏธ์ง์ ์ปจํ ์ด๋๋ฅผ ์ฌ๋ฌ ๊ฐ ๋ง๋ค ์ ์๋ค. ๊ทธ ๊ฒฐ๊ณผ๋ ์๋ฌ๋ฅผ ์ผ์ผํฌ ๊ฒ์ด๋ค.
์๋น์ค(์ปจํ ์ด๋) ๊ฐ์ dependency๋ฅผ ํํํ๋ค. service dependencies ๋ ๋ค์๊ณผ ๊ฐ์ ํ๋์ ์ ๋ฐํ๋ค.
docker-compose up
์ dependency order๋ก ์๋น์ค๋ค์ ์คํํ๋ค.docker-compose up SERVICE
๋ ์๋์ผ๋ก SERVICE
's dependencies ๋ค์ ํฌํจํ๋ค. ๐ปdocker-compose stop
์ ์์กด์ฑ ์์์ ๋ง์ถฐ์ ์๋น์ค๋ค์ ์ข
๋ฃ์ํจ๋ค.version: "3.9"
services:
web:
build: .
depends_on:
- db
- redis
redis:
image: redis
db:
image: postgres
๋ฐ์ดํฐ๋ฅผ ์ปจํ ์ด๋์ ์ ์ฅํ๋ ๊ฒ์ด ์๋๋ผ ํธ์คํธ(์ปจํ ์ด๋๋ฅผ ๋์ด ์ปดํจํฐ)์ ์ ์ฅํ๋ ๋ฐฉ์.
๋ณผ๋ฅจ์ host์ ๊ฒฝ๋ก ๋๋ named volumes๋ฅผ ํ ์๋น์ค์ sub-option์ผ๋ก ์ง์ ํ๋ configuration์ด๋ค.
์ฐ๋ฆฌ๋ single service(์ปจํ
์ด๋)์ part of a definition์ผ๋ก host path๋ฅผ ์ง์ ํ ์์๊ณ , ์ด ๊ฒฝ์ฐ์๋ top level volumes
ํค์๋ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ ํ์๊ฐ ์๋ค.
๊ทธ๋ฐ๋ฐ ์ฐ๋ฆฌ๊ฐ multiple services๋ค์ ๋ชจ๋ ์ด์ฉํ๋ volume ์ ์ง์ ํ๊ณ ์ถ์ ๊ฒฝ์ฐ์๋ ๊ทธ named volume์ top level volumes
์ ๋ช
์๋ฅผ ํด์ฃผ์ด์ผํ๋ค.
version: "3.9"
services:
web:
image: nginx:alpine
volumes:
- type: volume
source: mydata
target: /data
volume:
nocopy: true
- type: bind
source: ./static
target: /opt/app/static
db:
image: postgres:latest
volumes:
- "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
- "dbdata:/var/lib/postgresql/data"
volumes:
mydata:
dbdata:
volumes:
# Just specify a path and let the Engine create a volume
- /var/lib/mysql
# Specify an absolute path mapping
- /opt/data:/var/lib/mysql
# Path on the host, relative to the Compose file
- ./cache:/tmp/cache
# User-relative path
- ~/configs:/etc/configs/:ro
# Named volume
- datavolume:/var/lib/mysql
long syntax
type
: the mount typeย volume
,ย bind
,ย tmpfs
ย orย npipe
Docker ์ปจํ ์ด๋์ ๋ฐ์ดํฐ ์ ์ฅ (๋ณผ๋ฅจ/๋ฐ์ธ๋ ๋ง์ดํธ)
source
: the source of the mount, a path on the host for a bind mount, or the name of a volume defined in theย top-levelย volumes
ย key. Not applicable for a tmpfs mount.
target
: the path in the container where the volume is mounted
read_only
: flag to set the volume as read-only
bind
: configure additional bind options
propagation
: the propagation mode used for the bindvolume
: configure additional volume options
nocopy
: flag to disable copying of data from a container when a volume is createdtmpfs
: configure additional tmpfs options
size
: the size for the tmpfs mount in bytes