[๐Ÿณ Docker ๐Ÿณ] DockerCompose - ๋ช…์‹œ์ ์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ๊ด€๋ฆฌํ•˜๊ธฐ

Yohan_05ยท2023๋…„ 2์›” 2์ผ
0

Docker

๋ชฉ๋ก ๋ณด๊ธฐ
11/11
post-custom-banner

๋„์ปค ์ปดํฌ์ฆˆ

  • ๋‹จ์ผ ์„œ๋ฒ„์—์„œ ์—ฌ๋Ÿฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ”„๋กœ์ ํŠธ ๋‹ค๋ˆ„๋ฆฌ๋กœ ๋ฌถ์–ด์„œ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
  • docker-compose.yml ํŒŒ์ผ์„ ํ†ตํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ด€๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•จ.
  • ํ”„๋กœ์ ํŠธ ๋‹จ์œ„๋กœ ๋„์ปค ๋„คํŠธ์›Œํฌ์™€ ๋ณผ๋ฅจ ๊ด€๋ฆฌ
  • ํ”„๋กœ์ ํŠธ ๋‚ด ์„œ๋น„์Šค ๊ฐ„ ์˜์กด์„ฑ ์ •์˜ ๊ฐ€๋Šฅ
  • ํ”„๋กœ์ ํŠธ ๋‚ด ์„œ๋น„์Šค ๋””์Šค์ปค๋ฒ„๋ฆฌ ์ž๋™ํ™”
  • ์† ์‰ฌ์šด ์ปจํ…Œ์ด๋„ˆ ์ˆ˜ํ‰ ํ™•์žฅ

ํ”„๋กœ์ ํŠธ

  • ๋„์ปค ์ปดํฌ์ฆˆ์—์„œ ๋‹ค๋ฃจ๋Š” ์›Œํฌ์ŠคํŽ˜์ด์Šค ๋‹จ์œ„.
  • ํ•จ๊ป˜ ๊ด€๋ฆฌํ•˜๋Š” ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ์˜ ๋ฌถ์Œ.
  • ํ”„๋กœ์ ํŠธ ๋‹จ์œ„๋กœ ๊ธฐ๋ณธ ๋„์ปค ๋„คํŠธ์›Œํฌ๊ฐ€ ์ƒ์„ฑ๋จ.

์„œ๋น„์Šค

  • ๋„์ปค ์ปดํฌ์ฆˆ์—์„œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋‹จ์œ„.
  • scale ์„ ํ†ตํ•ด ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ์˜ ์ˆ˜ ํ™•์žฅ ๊ฐ€๋Šฅ.

์ปจํ…Œ์ด๋„ˆ

  • ์„œ๋น„์Šค๋ฅผ ํ†ตํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค.

docker-compose.yml

version, service, networks, volumes ์ด 4๊ฐœ์˜ ์ตœ์ƒ์œ„ ์˜ต์…˜

version

  • ๊ฐ€๋Šฅํ•œ ์ตœ์‹  ๋ฒ„์ „์„ ์‚ฌ์šฉ ๊ถŒ์žฅ
  • ๋„์ปค ์—”์ง„ ๋ฐ ๋„์ปค ์ปดํฌ์ฆˆ ๋ฒ„์ „์— ๋”ฐ๋ฅธ ํ˜ธํ™˜์„ฑ ๋งคํŠธ๋ฆญ์Šค๋ฅผ ์ฐธ๊ณ ํ•ด์•ผํ•จ(๊ณต์‹ ๋ฌธ์„œ ์ฐธ๊ณ )
  • ๋ฒ„์ „ 3๋ถ€ํ„ฐ docker swarm ์„œ๋น„์Šค๋ฅผ docker-compose.yml ๋กœ ์ €์œผ์ด ๊ฐ€๋Šฅ

๋„์ปค ์Šค์™?

  • ์—ฌ๋Ÿฌ ์„œ๋ฒ„๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์Šค์™ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ํ˜•์„ฑํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜ ์‹œ์Šคํ…œ. ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์™€ ๋™์ผ ๋ชฉ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์กŒ์ง€๋งŒ ์ธ๊ธฐ๋ฅผ ๋Œ์ง€ ๋ชปํ•จ.

service

  • ํ”„๋กœ์ ํŠธ ๋‚ด์— ๊ตฌ์„ฑ๋˜๋Š” ์—ฌ๋Ÿฌ ํ”„๋กœ์ ํŠธ๋ฅผ ์„œ๋ธŒ ํ‚ค๋ฅผ ํ†ตํ•ด์„œ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Œ.

networks

  • ๋„คํŠธ์›Œํฌ ํ‚ค ๋ฐ‘์—์„œ ์ •์˜ํ•ด์„œ ์‚ฌ์šฉ ๋””ํดํŠธ๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๊ธฐ๋ณธ ๋„คํŠธ์›Œํฌ๊ฐ€ ๋ธŒ๋ฆฟ์ง€ ๋ชจ๋“œ๋กœ ์ƒ์„ฑ๋จ.

volumes

  • ๋ณผ๋ฅจํ‚ค์—์„œ ์ •์˜์—์„œ ์‚ฌ์šฉ

docker compose ๋ช…๋ น์–ด

# Foreground๋กœ ๋„์ปค ์ปดํฌ์ฆˆ ํ”„๋กœ์ ํŠธ ์‹คํ–‰
$ docker-compose up

# Background๋กœ ๋„์ปค ์ปดํฌ์ฆˆ ํ”„๋กœ์ ํŠธ ์‹คํ–‰
$ docker-compose up -d

# ํ”„๋กœ์ ํŠธ ์ด๋ฆ„ my-project๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ๋„์ปค ์ปดํฌ์ฆˆ ํ”„๋กœ์ ํŠธ ์‹คํ–‰
$ docker-compose -p my-project up -d

# ํ”„๋กœ์ ํŠธ ๋‚ด ์ปจํ…Œ์ด๋„ˆ ๋ฐ ๋„คํŠธ์›Œํฌ ์ข…๋ฃŒ ๋ฐ ์ œ๊ฑฐ
$ docker-compose down

# ํ”„๋กœ์ ํŠธ ๋‚ด ์ปจํ…Œ์ด๋„ˆ, ๋„คํŠธ์›Œํฌ ๋ฐ ๋ณผ๋ฅจ ์ข…๋ฃŒ ๋ฐ ์ œ๊ฑฐ
$ docker-compose down -v

# ํ”„๋กœ์ ํŠธ ๋‚ด ์„œ๋น„์Šค ๋กœ๊ทธ ํ™•์ธ
$ docker-compose logs

# ํ”„๋กœ์ ํŠธ ๋‚ด ์ปจํ…Œ์ด๋„ˆ ์ด๋ฒคํŠธ ํ™•์ธ	
$ docker-compose events

# ํ”„๋กœ์ ํŠธ ๋‚ด ์ด๋ฏธ์ง€ ๋ชฉ๋ก
$ docker-compose images

# ํ”„๋กœ์ ํŠธ ๋‚ด ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก
$ docker-compose ps

# ํ”„๋กœ์ ํŠธ ๋‚ด ์‹คํ–‰์ค‘์ธ ํ”„๋กœ์„ธ์Šค ๋ชฉ๋ก
$ docker-compose top

์ฃผ์š” ์‚ฌ์šฉ ๋ชฉ์ 

๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์„ฑ

  • ํŠน์ • ํ”„๋กœ์ ํŠธ์˜ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์„ฑ ๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉ.
  • ํ”„๋กœ์ ํŠธ์˜ ์˜์กด์„ฑ์„ ์‰ฝ๊ฒŒ ๋„์šธ ์ˆ˜ ์žˆ์Œ.

์ž๋™ํ™”๋œ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ ๊ตฌ์„ฑ

  • CI/CD ํŒŒ์ดํ”„๋ผ์ธ ์ค‘ ์‰ฝ๊ฒŒ ๊ฒฉ๋ฆฌ๋œ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•˜์—ฌ ํ…Œ์ŠคํŠธ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅ

๋‹จ์ผ ํ˜ธ์ŠคํŠธ ๋‚ด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์„ ์–ธ์  ๊ด€๋ฆฌ

  • ๋‹จ์ผ ์„œ๋ฒ„์—์„œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ด€๋ฆฌํ•  ๋•Œ YAML ํŒŒ์ผ์„ ํ†ตํ•ด ์„ ์–ธ์ ์œผ๋กœ ๊ด€๋ฆฌ ๊ฐ€๋Šฅ.
profile
์•ˆ๋…•ํ•˜์„ธ์š” DevOps ์—”์ง€๋‹ˆ์–ด๋กœ ํ˜„์—…์—์„œ ํ™œ๋™์ค‘์ธ ์š”ํ•œ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€