๐Ÿ’พ Docker Compose ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ๋ช…๋ น์–ด๋ฅผ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

ํŒŒ์ผ ์ง€์ •

Docker Compose๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์ปค๋งจ๋“œ๊ฐ€ ์‹คํ–‰ํ•˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š”ย docker-compose.ymlย ๋˜๋Š”ย docker-compose.yaml๋ฅผ ์„ค์ • ํŒŒ์ผ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์ด๋ฆ„์ด๋‚˜ ๊ฒฝ๋กœ์˜ ํŒŒ์ผ์„ Docker Compose ์„ค์ • ํŒŒ์ผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ๋‹ค๋ฉดย -fย ์˜ต์…˜์œผ๋กœ ๋ช…์‹œ๋ฅผ ํ•ด์ค๋‹ˆ๋‹ค.

# -f ์˜ต์…˜์œผ๋กœ ํŒŒ์ผ์ผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
$ docker-compose -f docker-compose-local.yml up

# -f ์˜ต์…˜์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์„ค์ • ํŒŒ์ผ์„ ์‚ฌ์šฉํ•  ๋•Œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
# ์ด ๋•Œ๋Š” ๋‚˜์ค‘์— ๋‚˜์˜ค๋Š” ์„ค์ •์ด ์•ž์— ๋‚˜์˜ค๋Š” ์„ค์ •๋ณด๋‹ค ์šฐ์„ ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
$ docker-compose -f docker-compose.yml -f docker-compose-test.yml up


์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ/์‹คํ–‰

docker-compose up ์ปค๋งจ๋“œ๋Š” Docker Compose์— ์ •์˜๋˜์–ด ์žˆ๋Š” ๋ชจ๋“  ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ•œ ๋ฒˆ์— ์ƒ์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

# -d ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„์›๋‹ˆ๋‹ค.
# -d ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด ํ˜„์žฌ ํ„ฐ๋ฏธ๋„์— ๋กœ๊ทธ๊ฐ€ ์ถœ๋ ฅ๋˜๊ณ , Ctrl+c๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ข…๋ฃŒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
$ docker-compose up -d


์ปจํ…Œ์ด๋„ˆ ์ •์ง€/์‚ญ์ œ

docker-compose downย ์ปค๋งจ๋“œ๋Š” Docker Compose์— ์ •์˜๋˜์–ด ์žˆ๋Š” ๋ชจ๋“  ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ•œ ๋ฒˆ์— ์ •์ง€์‹œํ‚ค๊ณ  ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.

# -v ์˜ต์…˜์„ ์ฃผ๋ฉด docker-compose.yml์— ์ •์˜๋œ ๋ณผ๋ฅจ์„ ์‚ญ์ œํ•˜๋ฉฐ down ํ•ฉ๋‹ˆ๋‹ค.
$ docker-compose down -v


์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘

docker-compose startย ์ปค๋งจ๋“œ๋Š” ๋‚ด๋ ค๊ฐ€ ์žˆ๋Š” ์žˆ๋Š” ํŠน์ • ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์˜ฌ๋ฆฌ๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. docker-compose upย ์ปค๋งจ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด๋„ ๋‚ด๋ ค๊ฐ„ ์„œ๋น„์Šค๋ฅผ ์•Œ์•„์„œ ์˜ฌ๋ ค์ค๋‹ˆ๋‹ค.

$ docker-compose start web


์ปจํ…Œ์ด๋„ˆ ์ •์ง€

docker-compose stopย ์ปค๋งจ๋“œ๋Š”ย ๋Œ์•„๊ธฐ๊ณ  ์žˆ๋Š” ํŠน์ • ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ •์ง€์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

$ docker-compose stop web


์ปจํ…Œ์ด๋„ˆ ์กฐํšŒ

docker-compose psย ์ปค๋งจ๋“œ๋Š” Docker Compose์— ์ •์˜๋˜์–ด ์žˆ๋Š” ๋ชจ๋“  ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก์„ ์กฐํšŒํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

$ docker-compose ps

      Name                    Command               State           Ports
----------------------------------------------------------------------------------
django-app_db_1    docker-entrypoint.sh postgres    Up      5432/tcp
django-app_web_1   python manage.py runserver ...   Up      0.0.0.0:8000->8000/tcp


์ปจํ…Œ์ด๋„ˆ ๋กœ๊ทธ

docker-compose logsย ์ปค๋งจ๋“œ๋Š” ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ์˜ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋ฉฐ, ๋ณดํ†ตย -f ์˜ต์…˜์„ ๋ถ™์—ฌ์„œ ์‹ค์‹œ๊ฐ„ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. -f ๋‹ค์Œ์— ์„œ๋น„์Šค๋ช…์„ ์ž…๋ ฅํ•˜๋ฉด ํ•ด๋‹น ์„œ๋น„์Šค์˜ ๋กœ๊ทธ๋งŒ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$ docker-compose logs -f web

web_1  | May 30, 2020 - 22:16:29
web_1  | Django version 3.0.6, using settings 'our_project.settings'
web_1  | Starting development server at http://0:8000/
web_1  | Quit the server with CONTROL-C.


๋ช…๋ น์–ด ์ „๋‹ฌ

docker-compose execย ์ปค๋งจ๋“œ๋Š” ์‹คํ–‰ ์ค‘์ธ ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋Œ€์ƒ์œผ๋กœ ์–ด๋–ค ๋ช…๋ น์–ด๋ฅผ ๋‚ ๋ฆด ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

$ docker-compose exec -it web /bin/bash


์ผํšŒ์„ฑ ๋ช…๋ น์–ด

docker-compose run ์ปค๋งจ๋“œ๋Š” ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ์˜ ํŠน์ • ๋ช…๋ น์–ด๋ฅผ ์ผํšŒ์„ฑ์œผ๋กœ ์‹คํ–‰ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

$ docker compose run web bash


์„ค์ • ํ™•์ธ

docker-compose config ์ปค๋งจ๋“œ๋Š” Docker Compose ์„ค์ •์„ ํ™•์ธํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.ย -fย ์˜ต์…˜์œผ๋กœ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์„ค์ • ํŒŒ์ผ์„ ์‚ฌ์šฉํ•  ๋•Œ, ์ตœ์ข…์ ์œผ๋กœ ์–ด๋–ป๊ฒŒ ์„ค์ •์ด ์ ์šฉ๋˜๋Š”์ง€ ํ™•์ธํ•ด๋ณผ ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

$ docker compose config


๋ ˆํผ๋Ÿฐ์Šค ์ฐธ๊ณ 

docker-compose

๐Ÿ™‡๐Ÿปโ€โ™‚๏ธ ์ฐธ๊ณ ์‚ฌ์ดํŠธ

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ