728x90
๋ฐ˜์‘ํ˜•

10์žฅ ๋„์ปค ์ปดํฌ์ฆˆ๋ฅผ ์ด์šฉํ•œ ์—ฌ๋Ÿฌ ํ™˜๊ฒฝ ๊ตฌ์„ฑ

  • ๋ฐฐํฌ๊ฐ€ ์‹คํŒจํ•˜๋Š” ์ฃผ๋œ ์›์ธ์€ ํ™˜๊ฒฝ ์ฐจ์ด๋‹ค.
  • ๋„์ปค๋Š” ํŒจํ‚ค์ง€์— ๋ชจ๋“  ์˜์กด ๋ชจ๋“ˆ์ด ํ•จ๊ป˜ ๋“ค์–ด๊ฐ€๊ธฐ ๋–„๋ฌธ์— ํ•ด๋‹น ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ํ•˜์ง€๋งŒ, ํ™˜๊ฒฝ์—๋”ฐ๋ผ ๋™์ž‘์„ ๋‹ค๋ฅด๊ฒŒ ํ•ด์•ผ ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค.
  • ๋„์ปค ์ปดํฌ์ฆˆ์˜ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

10.1 ๋„์ปค ์ปดํฌ์ฆˆ๋กœ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌํ•˜๊ธฐ

  • ๊ฐ™์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฒ„์ „์„ ๋‹ค๋ฅด๊ฒŒ ๊ตฌ๋™ํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋”ฐ.
  • ์—ฌ๋Ÿฌ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•ด ์‚ฌ์šฉํ•˜๋ ค๋ฉด, ํ™˜๊ฒฝ๋งˆ๋‹ค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋‹ค๋ฅด๊ฒŒ ๋™์ž‘ํ•˜๊ฒŒ ํ•ด์•ผ ํ•œ๋‹ค.
  • ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ์—์„œ ํ•ด๋‹น ๊ตฌ์„ฑ์„ ๋ช…์‹œํ•ด์•ผ ํ•œ๋‹ค.
  • ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ์€ ๋ ˆ์ด๋ธ” ๋ช…๋ช… ๊ทœ์น™์„ ํ†ตํ•ด ๋„์ปค ๋ฆฌ์†Œ์Šค๋ฅผ ์ปจํ…Œ์ด๋„ˆ์™€ ์„œ๋น„์Šค๋กœ ๊ตฌ๋ถ„ํ•˜๋ฉฐ ๊ด€๋ฆฌํ•œ๋‹ค.

๋„์ปค ์ปดํฌ์ฆˆ ๋ฆฌ์†Œ์Šค ์ด๋ฆ„ ๊ทœ์น™

  • ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ์ด ์œ„์น˜ํ•œ ๋””๋ ‰ํ† ๋ฆฌ์˜ ์ด๋ฆ„์„ ๊ธฐ๋ณธ์œผ๋กœ ํ”„๋กœ์ ํŠธ ๋ผ๊ณ  ํ•œ๋‹ค.
  • ํ”„๋กœ์ ํŠธ๋Š” ๋„์ปค ๋ฆฌ์†Œ์Šค๊ฐ€ ์–ด๋–ค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ผ๋ถ€์ธ์ง€ ์•„๋‹Œ์ง€๋ฅผ ํŒ๋ณ„ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค.
  • ๋„์ปค ์ปดํฌ์ฆˆ์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ๋ชจ๋“  ๊ฐ์ฒด๋ฅผ ๋ฆฌ์†Œ์Šค ๋ผ๊ณ  ํ•œ๋‹ค.
  • ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋„์ปค ์ปดํฌ์ฆˆ ํ”„๋กœ์ ํŠธ๋ฅผ ๋™์‹œ์— ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ, ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์„ ์ ‘๋‘์‚ฌ๋กœ ๋ถ™์—ฌ์„œ ๊ตฌ๋ถ„ํ•œ๋‹ค.
  • ๋™์ผํ•œ ์„œ๋น„์Šค์˜ ๋ณต์ˆ˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด ์ ‘๋ฏธ์‚ฌ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆซ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
# docker compose ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœ์ œํŠธ ์ด๋ฆ„ ๋ณ€๊ฒฝ
$ docker compose -f ./todo-list/docker-compose.yml -p todo-test up -d

$ docker ps

CONTAINER ID   IMAGE                   COMMAND                 CREATED         STATUS         PORTS                                       NAMES
e0645d889591   diamol/ch06-todo-list   "dotnet ToDoList.dll"   2 seconds ago   Up 1 second    0.0.0.0:32776->80/tcp, [::]:32776->80/tcp   todo-test-todo-web-1
290efebd5094   diamol/ch06-todo-list   "dotnet ToDoList.dll"   7 minutes ago   Up 7 minutes   0.0.0.0:32775->80/tcp, [::]:32775->80/tcp   todo-list-todo-web-1

$ docker container port todo-test_todo_web_1 80
  • ๋ณต์ˆ˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์ธ์Šคํ„ด์Šค ๊ฐ๊ฐ์˜ ์„ค์ •์„ ์ฐพ์•„์„œ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์€ ๋ฒˆ๊ฑฐ๋กญ๋‹ค.
  • ๋งค๋ฒˆ ์ปดํฌ์ฆˆ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜์—ฌ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์€ ๋น„ํšจ์œจ์ ์ด๊ณ  ๊ด€๋ฆฌ๊ฐ€ ์–ด๋ ต๋‹ค.
  • ๋„์ปค ์ปดํฌ์ฆˆ๋Š” ์„ค์ •์„ ์˜ค๋ฒ„๋ผ์ด๋“œํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜์—ฌ ์œ„์˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ๋‹ค.

10.2 ๋„์ปค ์ปดํฌ์ฆˆ์˜ ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ

  • ํ•˜๋‚˜์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์—ฌ๋Ÿฌ ์„ค์ •์œผ๋กœ ์‹คํ–‰ํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ, ๋Œ€๋ถ€๋ถ„์€ ์ปดํฌ์ฆˆ ํŒŒ์ผ์„ ์—ฌ๋Ÿฌ๊ฐœ ์ •์˜ํ•˜์—ฌ ์‚ฌ์šฉํ•œ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜, ์ด ๋ฐฉ๋ฒ•์€ ์œ ์ง€๋ณด์ˆ˜ ์ธก๋ฉด์—์„œ ๋ฐ”๋žŒ์งํ•˜์ง€ ์•Š๋‹ค.
  • ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋„์ปค ์ปดํฌ์ฆˆ๋Š” ์—ฌ๋Ÿฌ ํŒŒ์ผ์„ ํ•ฉ์ณ ์ปดํฌ์ฆˆ ํŒŒ์ผ์„ ๊ตฌ์„ฑํ•˜๊ณ , ๋‚˜์ค‘์— ์ง€์ •๋œ ํŒŒ์ผ์˜ ๋‚ด์šฉ์ด ์ด์ „ ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ๋ฎ์–ด์“ด๋‹ค.
# docker-compose.yml ๊ธฐ๋ณธ ํŒŒ์ผ
$ vi docker-compose.yml

services:
	todo-web:
		imageL: diamol/ch06-todo-list
		ports:
			- 80
		environment:
			- Database:Provider=Sqlite
		networks:
			- app-net

# docker-compose-v2.yml ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ
$ vi docker-compose-v2.yml

services:
	todo-web:
		image: diamol/ch06-todo-list:v2
		
$ docker compose -f docker-compose.yml -f docker-compose-v2.yml config

name: todo-list
services:
  todo-web:
    environment:
      Database:Provider: Sqlite
    image: diamol/ch06-todo-list:v2
    networks:
      app-net: null
    ports:
      - mode: ingress
        target: 80
        protocol: tcp
networks:
  app-net:
    name: todo-list_app-net
  • ๋‘ docker-compose ํŒŒ์„ ๋ชจ๋‘ ์œ ํšจํ•œ ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ ํ˜•์‹์„ ์œ ์ง€ํ•ด์•ผ ํ•œ๋‹ค.
  • ๊ธฐ๋ณธ์ด ๋˜๋Š” ์ปดํฌ์ฆˆ ํŒŒ์ผ์˜ ๊ตฌ์กฐ๋ฅผ ์œ ์ง€ํ•ด์•ผ ๋„์ปค ์ปดํฌ์ฆˆ๊ฐ€ ๋‘ ์ •์˜๋ฅผ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.
  • config ๋ช…๋ น์–ด๋ฅผ ํ†ตํŒจ ๋ณ‘ํ•ฉ๋œ ํŒŒ์ผ์˜ ๋‚ด์šฉ์ด ์œ ํšจํ•œ์ง€ ๊ฒ€์‚ฌํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋„์ปค ์ปดํฌ์ฆˆ๊ฐ€ ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ์„ ๋ณ‘ํ•ฉํ•˜๋Š” ์ˆœ์„œ๋Š” ์ธ์ž์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ฅธ๋‹ค.
$ docker compose -f docker-compose.yml -f docker-compose-dev.yml -p number-dev up -d
[+] Running 3/3
 โœ” Network numbers-dev                 Created                                                                                                                                                         0.1s 
 โœ” Container number-dev-numbers-web-1  Started                                                                                                                                                         0.3s 
 โœ” Container number-dev-numbers-api-1  Started                                                                                                                                                         0.2s 
$ docker compose -f docker-compose.yml -f docker-compose-test.yml -p number-test up -d
[+] Running 3/3
 โœ” Network numbers-test                 Created                                                                                                                                                        0.1s 
 โœ” Container number-test-numbers-api-1  Started                                                                                                                                                        0.2s 
 โœ” Container number-test-numbers-web-1  Started                                                                                                                                                        0.2s 
$ docker compose -f docker-compose.yml -f docker-compose-uat.yml -p number-uat up -d
[+] Running 3/3
 โœ” Network numbers-uat                 Created                                                                                                                                                         0.1s 
 โœ” Container number-uat-numbers-api-1  Started                                                                                                                                                         0.2s 
 โœ” Container number-uat-numbers-web-1  Started                                                              
 
 $ docker compose -f docker-compose.yml -f docker-compose-test.yml -p number-test down
[+] Running 3/3
 โœ” Container number-test-numbers-api-1  Removed                                                                                                                                                        0.1s 
 โœ” Container number-test-numbers-web-1  Removed                                                                                                                                                       10.2s 
 โœ” Network numbers-test                 Removed                                                
  • ํ™˜๊ฒฝ๋ณ„๋กœ ์‹คํ–‰๋œ ์ปจํ…Œ์ด๋„ˆ๋Š” ๋„๋ฉ”์ธ ๋„ค์ž„์„ ์‚ฌ์šฉํ•ด ์„œ๋กœ๋ฅผ ์‹๋ณ„ํ•˜์ง€๋งŒ, ๊ฐ™์€ ๋„์ปค ๋„คํŠธ์›Œํฌ์— ์ ‘์†ํ•œ ์ปจํ…Œ์ด๋„ˆ๋ผ๋ฆฌ๋งŒ ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์žฌ์ •์˜ ์ด์ ์ด ์กด์žฌํ•œ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜, ์˜ค๋ฒ„๋ผ์ด๋“œ ๊ด€๋ฆฌ์— ๋“œ๋Š” ์˜ค๋ฒ„ํ—ค๋“œ๋„ ๋ฐœ์ƒํ•œ๋‹ค.
  • ๋”ฐ๋ผ์„œ, ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ๊ด€๋ จ ๋ฐฐํฌ ๊ด€๋ จ ์ž๋™ํ™” ๊ตฌ์„ฑํ•˜์—ฌ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ์ตœ์†Œํ™” ํ•˜๋Š”๊ฒƒ์ด ์ข‹๋‹ค.

10.3 ํ™˜๊ฒฝ ๋ณ€์ˆ˜์™€ ๋น„๋ฐ€๊ฐ’์„ ์ด์šฉํ•ด ์„ค์ • ์ฃผ์ž…ํ•˜๊ธฐ

  • ๋„์ปค ์ปดํฌ์ฆˆ๋Š” ๊ฐ ์ปจํ…Œ์ด๋„ˆ์— ํ•„์š”ํ•œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜์™€ ๋น„๋ฐ€๊ฐ’์„ ์„ค์ •ํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์œ ์—ฐํ•˜๊ฒŒ ์šด์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.
# docker-compose.yml
services:
	todo-web:
		image: diamol/ch06-todo-list
		secrets:
			- source: todo-db-connection
			  target: /app/config/secrets.json
  • source: ์›๋ณธ ์œ„์น˜, ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์ด ๋น„๋ฐ€๊ฐ’์„ ์ฝ์–ด์˜ค๋Š” ๊ณณ.
  • target: ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์— ๋น„๋ฐ€๊ฐ’์ด ์œ„์น˜ํ•  ๊ฒฝ๋กœ.
# docker-compmose-dev.yml
# ๊ฐœ๋ฐœ ํ™˜๊ฒฝ๋งŒ์„ ์œ„ํ•œ ์ถ”๊ฐ€ ์„ค์ •๊ณผ ๋น„๋ฐ€๊ฐ’์ด ์ •์˜๋œ ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ
services:
	todo-web:
		ports:
			- 8089:80
		environment:
			- Database:Provider=Sqlite
		env_file:
			- ./config/logging.debug.env
secrets:
	todo-db-connection:
		file: ./config/empty.json
			
  • environment
    • ์ปจํ…Œ์ด๋„ˆ ์•ˆ์—์„œ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
  • env_file
    • ํ…์ŠคํŠธ ํŒŒ์ผ์˜ ๊ฒฝ๋กœ๋ฅผ ๊ฐ’์œผ๋กœ ๋ฐ›๋Š”๋‹ค.
    • ์ด ํŒŒ์ผ์— ์ •์˜๋œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ์ปจํ…Œ์ด๋„ˆ์— ์ ์šฉ๋œ๋‹ค.
    • ํ…์ŠคํŠธ ํŒŒ์ผ์— ๋ณ€์ˆ˜ ์ด๋ฆ„๊ณผ ๊ฐ’์„ ๋“ฑํ˜ธ๋กœ ๊ตฌ๋ถ„ํ•ด ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ •์˜ํ•œ๋‹ค.
  • secrets
    • ์ปดํฌ์ฆˆ ํŒŒ์ผ์˜ ์ตœ์ƒ์œ„ ํ”„๋กœํผํ‹ฐ
    • todo-db-connection์˜ ์‹ค์ œ ๊ฐ’ ํ˜น์€ ๊ฒฝ๋กœ๊ฐ€ ์ •์˜๋œ๋‹ค.
$ docker compose -f ./todo-list-configured/docekr-compose.yml -f ./todo-list-configured/docker-compose-dev.yml -p todo-dev up -d

Creating network "todo-dev_default" with the default driver
Creating todo-dev_todo-web_1 ... done
  • ๋„์ปค ์ปดํฌ์ฆˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ•œ ๊ฐœ๋งˆ๋‹ค ๋„์ปค ๋„คํŠธ์›Œํฌ๋ฅผ ํ•˜๋‚˜์”ฉ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ์ปดํฌ์ฆˆ ํŒŒ์ผ์— ์ •์˜๋œ ๋„คํŠธ์›Œํฌ๊ฐ€ ์—†์–ด๋„ ๊ธฐ๋ณธ ๋„คํŠธ์›Œํฌ์— ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์—ฐ๊ฒฐํ•œ๋‹ค.

Docker ๊ธฐ๋ณธ ๋„คํŠธ์›Œํฌ (bridge)

  • ๋„์ปค ์ปดํฌ์ฆˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์—ฌ๋Ÿฌ ์„œ๋น„์Šค ๊ฐ„์˜ ๋„คํŠธ์›Œํ‚น์„ ์‰ฝ๊ฒŒ ์„ค์ •ํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋„๊ตฌ์ด๋‹ค.
  • Docker ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” bridge ๋ผ๋Š” ๊ฐ€์ƒ ๋„คํŠธ์›Œํฌ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
  • bridge ๋Š” ๋„์ปค ๋ฐ๋ชฌ์ด ๊ด€๋ฆฌํ•˜๋Š” ๊ฐ€์ƒ ๋„คํŠธ์›Œํฌ๋กœ, ๋™์ผํ•œ ๋ธŒ๋ฆฌ์ง€ ๋„คํŠธ์›Œํฌ์— ์—ฐ๊ฒฐ๋œ ์ปจํ…Œ์ด๋„ˆ๋“ค์€ ์„œ๋กœ IP ์ฃผ์†Œ๋ฅผ ํ†ตํ•ด ํ†ต์‹ ํ•œ๋‹ค.
  • ๋˜ํ•œ, bridge ๋„คํŠธ์›Œํฌ๋Š” ์™ธ๋ถ€ ๋„คํŠธ์›Œํฌ์™€ ๊ฒฉ๋ฆฌ๋˜์–ด ์žˆ์–ด ๋ณด์•ˆ์„ ๊ฐ•ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์ปดํฌ์ฆˆ ํŒŒ์ผ์—์„œ ๋„คํŠธ์›Œํฌ๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ •์˜ํ•˜์ง€ ์•Š์œผ๋ฉด, Docker ๋Š” ๊ธฐ๋ณธ ๋„คํŠธ์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์—ฐ๊ฒฐํ•œ๋‹ค.

ํ˜ธ์ŠคํŠธ ์ปดํ“จํ„ฐ์˜ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ปจํ…Œ์ด๋„ˆ์— ์ „๋‹ฌํ•˜๊ธฐ

todo-web:
	ports:
		- "$(TODO_WEB_PORT):80"
	environment:
		- Database:Provider=Postgres
	env_file:
		- ./config/logging.information.env
	networks:
		- app-net
$ vi .env

TODO_WEB_PORT=8877
TODO_DB_PORT=5432

COMPOSE_PATH_SEPARATOR=;
COMPOSE_FILE=docker-compose.yml;docker-compose-test.yml
COMPOSE_PROJECT_NAME=todo_ch10
  • .env ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋ฉด docker-compose.yml ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ , ์„ค์ •๊ฐ’์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ด์‹์„ฑ์ด ํ–ฅ์ƒ ๋œ๋‹ค.
  • env_file ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์™ธ๋ถ€ ํŒŒ์ผ์—์„œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ฝ์–ด ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.
  • ์ปดํฌ์ฆˆ ํŒŒ์ผ์—์„œ $ ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ฐจ๋ชจํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์ปดํฌ์ฆˆ ํŒŒ์ผ๊ณผ ๋™์ผํ•œ ๋””๋ ‰ํ† ๋ฆฌ์—์„œ .env ํŒŒ์ผ์„ ์ƒ์„ฑ ๋ฐ ์ •์˜ํ•˜์—ฌ, ์ปดํฌ์ฆˆ๋Š” ํ•ด๋‹น ํŒŒ์ผ์„ ์ž๋™์œผ๋กœ ์ฝ์–ด์˜จ๋‹ค.

10.4 ํ™•์žฅ ํ•„๋“œ๋กœ ์ค‘๋ณต ์ œ๊ฑฐํ•˜๊ธฐ

  • ๋„์ปค ์ปดํฌ์ฆˆ๋ฅผ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋ฉด ์„œ๋น„์Šค ๊ฐ„ ๋งŽ์€ ์„ค์ •๊ฐ’์„ ๊ณต์œ ํ•˜๋Š” ์ปดํฌ์ฆˆ ํŒŒ์ผ์˜ ๋ฉ์น˜๊ฐ€ ์ ์  ์ปค์ง€๋Š” ๊ฒƒ์ด ๋ฌธ์ œ๋‹ค.
  • ์ด๋Ÿฐ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ํ™•์žฅ ํ•„๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ํ™•์žฅ ํ•„๋“œ๋Š” ์ปดํฌ์ฆˆ ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ฒ ์ŠคํŠธ ํ”„๋ ‰ํ‹ฐ์Šค ์ค‘ ํ•œ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด๋‹ค.
  • ํ™•์žฅ ํ•„๋“œ๋ฅผ ์ž˜ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ์ค‘๋ณต๋˜๋Š” ์„ค์ •์„ ์ƒ๋‹น๋ถ€๋ถ„ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ํ•˜์ง€๋งŒ, ํ™•์žฅ ํ•„๋“œ์—๋„ ์—ฌ๋Ÿฌ ์ปดํฌ์ฆˆ ํŒŒ์ผ์— ํ•œ๊บผ๋ฒˆ์— ์ ์šฉํ•  ์ˆ˜ ์—†๋‹ค.
  • ๋”ฐ๋ผ์„œ, ์ฝ”์–ด ์ปดํฌ์ฆˆ ํŒŒ์ผ์— ์ •์˜๋œ ํ™•์žฅ ํ•„๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ์—์„œ ์‚ฌ์šฉํ• ์ˆ˜๋Š” ์—†๋‹ค.
version: "3.7"

x-labels: &logging
  logging:
    options:
      max-size: '100m'
      max-file: '10'

x-labels: &labels
  app-name: image-gallery

services:
  accesslog:
    <<: *logging
    labels:
      <<: *labels

  iotd:
    ports:
      - 8080:80
    <<: *logging
    labels:
      <<: *labels
      public: api

  image-gallery:
    ports:
      - 80:80
    <<: *logging
    labels:
      <<: *labels
      public: web

  prometheus:
    image: diamol/ch09-prometheus
    ports:
      - "9090:9090"
    environment:

  • ๋„์ปค ์ปดํฌ์ฆˆ์˜ ํ™•์žฅ ํ•„๋“œ๋Š” ์•ฐํผ์ƒŒ๋“œ ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค.
  • <<:* ์œ„์น˜์— ํ•ด๋‹น YAML ํŒŒ์ผ์˜ ํ™•์žฅ ํ•„๋“œ๊ฐ’์ด ๋ณ‘ํ•ฉ๋œ๋‹ค.
$ docker-compose -f ./image-gallery/docker-compose.yml -f ./image-gallery/docker-compose-prod.yml config

WARN[0000] /home/gwanii/docker_textbook/080258-main/ch10/exercises/image-gallery/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
WARN[0000] The "HOST_IP" variable is not set. Defaulting to a blank string. 
WARN[0000] /home/gwanii/docker_textbook/080258-main/ch10/exercises/image-gallery/docker-compose-prod.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
name: image-gallery
services:
  accesslog:
    image: diamol/ch09-access-log
    labels:
      app-name: image-gallery
    logging:
      options:
        max-file: "10"
        max-size: 100m
    networks:
      app-net: null
  grafana:
    depends_on:
      prometheus:
        condition: service_started
        required: true
    image: diamol/ch09-grafana
    labels:
      app-name: image-gallery
    logging:
      options:
        max-file: "10"
        max-size: 100m
    networks:
      app-net: null
    ports:
      - mode: ingress
        target: 3000
        published: "3000"
        protocol: tcp
  image-gallery:
    image: diamol/ch09-image-gallery
    labels:
      app-name: image-gallery
      public: web
    logging:
      options:
        max-file: "10"
        max-size: 100m
    networks:
      app-net: null
    ports:
      - mode: ingress
        target: 80
        published: "80"
        protocol: tcp
  iotd:
    image: diamol/ch09-image-of-the-day
    labels:
      app-name: image-gallery
      public: api
    logging:
      options:
        max-file: "10"
        max-size: 100m
    networks:
      app-net: null
    ports:
      - mode: ingress
        target: 80
        published: "8080"
        protocol: tcp
  prometheus:
    environment:
      DOCKER_HOST: ""
    image: diamol/ch09-prometheus
    labels:
      app-name: image-gallery
    logging:
      options:
        max-file: "10"
        max-size: 100m
    networks:
      app-net: null
    ports:
      - mode: ingress
        target: 9090
        published: "9090"
        protocol: tcp
networks:
  app-net:
    name: image-gallery-prod
x-labels:
  app-name: image-gallery
x-logging:
  logging:
    options:
      max-file: "10"
      max-size: 100m

์ฐธ๊ณ  - ์ฑ… ์˜ˆ์‹œ๋ฅผ ๋”ฐ๋ผํ•  ๊ฒฝ์šฐ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ.

  • ์ฑ…์— ๋‚˜์™€์žˆ๋Š” ์˜ˆ์ œ๋ฅผ ๋”ฐ๋ผํ•  ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒƒ์ด๋‹ค.
WARN[0000] /home/gwanii/docker_textbook/080258-main/ch10/exercises/image-gallery/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
yaml: unmarshal errors:
  line 9: mapping key "x-labels" already defined at line 3
  • Docker Compose V2 ๋ฒ„์ „๋ถ€ํ„ฐ๋Š” x-fileds ๊ฐ€ ์ค‘๋ณต์œผ๋กœ ์„ ์–ธ๋˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์ •ํ™•ํžˆ๋Š” ์‚ฌ์šฉํ•  ์ˆ˜๋Š” ์žˆ์ง€๋งŒ, ๊ถŒ์žฅ๋˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•œ๋‹ค.
  • ๊ทธ ์ด์œ ๋Š” ์œ ์ง€๋ณด์ˆ˜ ์ฐจ์›์—์„œ ํ™•์žฅ ํ•„๋“œ๋ฅผ ๋ช…ํ™•ํžˆ ๋ถ„๋ฆฌํ•˜๋Š” ๋ฐฉ์‹ ์‚ฌ์šฉ์„ ๊ถŒ์žฅํ•œ๋‹ค.
x-logging: &logging
  logging:
    options:
      max-size: '100m'
      max-file: '10'

x-labels: &labels
  app-name: image-gallery
  • ์ด์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด Docker Compose V2 ๋ฐฉ์‹์—์„œ ๊ถŒ์žฅ๋˜๋Š” ๋ฐฉ์‹์ด๋ผ๊ณ  ํ•œ๋‹ค.

10.5 ๋„์ปค๋ฅผ ์ด์šฉํ•œ ์„ค์ • ์›Œํฌํ”Œ๋กœ ์ดํ•ดํ•˜๊ธฐ

  • ์„ค์ • ์›Œํฌํ”Œ๋กœ์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ ์€ ๋ชจ๋“  ํ™˜๊ฒฝ์—์„œ ๊ฐ™์€ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.
  • ๋ชจ๋“  ํ™˜๊ฒฝ์—์„œ ๊ฐ™์€ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ, ์ปจํ…Œ์ด๋„ˆ ํ”Œ๋žซํผ์—์„œ ์ œ๊ณต๋œ ์„ค์ •๊ฐ’์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ๋™์ž‘๋˜๋Š” ๊ฒƒ์ด ํ•ต์‹ฌ์ด๋‹ค.
  • ๋„์ปค ์ปดํฌ์ฆˆ๋ฅผ ์ด์šฉํ•ด ๊ฐ ๋‹จ๊ณ„๋ณ„ ์„ค์ • ์›Œํฌํ”Œ๋กœ ์„ค์ • ๋ฐฉ๋ฒ•์„ ํฌ๊ฒŒ 3๊ฐ€์ง€๋กœ ๋ถ„๋ฅ˜ ํ•˜์˜€๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ์„ฑ ์š”์†Œ์˜ ์กฐํ•ฉ

  • ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜์—ฌ, ๊ณตํ†ต๋œ ์„œ๋น„์Šค๋Š” ์žฌ์‚ฌ์šฉํ•˜๊ณ  ํ•„์š”ํ•œ ์„ค์ •์„ ๊น”๋”ํ•˜๊ณ  ๊ฐ„ํŽธํ•˜๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

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

  • ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ๊ณผ ๋„์ปค ๋„คํŠธ์›Œํฌ๋กœ ๊ฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ถ„๋ฆฌํ•˜๋ฉด์„œ ๋‹จ์ผ ์„œ๋ฒ„์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ค์ •

  • ์˜ค๋ฒ„๋ผ์ด๋“œ ํŒŒ์ผ๊ณผ ํ™˜๊ฒฝ ํŒŒ์ผ, ๋น„๋ฐ€๊ฐ’์„ ์ด์šฉํ•ด ์ƒํ™ฉ์— ๋งž๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ค์ • ๊ฐ’์„ ์ปจํ…Œ์ด๋„ˆ์— ์ฃผ์ž…ํ•  ์ˆ˜ ์žˆ๋‹ค.
728x90
๋ฐ˜์‘ํ˜•
MyeongDev