๋ณธ๋ฌธ์œผ๋กœ ๋ฐ”๋กœ๊ฐ€๊ธฐ

:alert:

https://docs.docker.com/compose/

 


 

๐Ÿณ docker compose ์„ค์น˜

 

linux์˜ ๊ฒฝ์šฐ docker compose๋ฅผ ๋ณ„๋„๋กœ ์„ค์น˜ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

https://docs.docker.com/compose/install/

 

sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

docker for mac/windows๋กœ ์„ค์น˜ํ•œ ๊ฒฝ์šฐ docker๋Š” ์ด๋ฏธ docker-compose๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๋‹ค.

 

์„ค์น˜๊ฐ€ ์ œ๋Œ€๋กœ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด version ์ •๋ณด๋ฅผ ์ฐ์–ด๋ณด์ž.

docker-compose version

 

 

๐Ÿณ docker-compose ์™œ ์”€? (= ๊ทธ๋ƒฅ ๋„์ปค ์“ฐ๋ฉด ๋ญ๊ฐ€ ๋ถˆํŽธํ•จ?)

 

์š”์•ฝํ•˜์ž๋ฉด, ๋„์ปค ๋ช…๋ น์–ด๋ฅผ ํŒŒ์ผ๋กœ ๊ด€๋ฆฌํ•ด์„œ ๋ณต์žกํ•œ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋ฐ ๋„์ปค ๋„คํŠธ์›Œํฌ๋ฅผ ๊ตฌ์„ฑํ•˜๊ธฐ์— ์šฉ์ดํ•˜๋‹ค๋Š” ๊ฒƒ์ด๋‹ค!

 

1. docker ๋ณด๋‹ค ๊ฐ„๊ฒฐํ•จ

 

๊ฐ„๋‹จํ•œ html์„ ๋งŒ๋“ค๊ณ  nginx๋กœ ์—ฐ๊ฒฐํ•˜๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด docker ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค.

์ปจํ…Œ์ด๋„ˆ 80 ํฌํŠธ๋ฅผ ๋กœ์ปฌ 8080 ํฌํŠธ์™€ ๋งคํ•‘ํ•˜๊ณ , ์ข…๋ฃŒ์‹œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ญ์ œํ•˜๊ธฐ ์œ„ํ•ด --rm ์˜ต์…˜์„ ์ฃผ์—ˆ๊ณ 

๋กœ์ปฌ์˜ ํŠน์ • ๊ฒฝ๋กœ์˜ ํด๋” ํ˜น์€ ํŒŒ์ผ์„ ์ฐธ๊ณ ํ•˜๋„๋ก volume ์˜ต์…˜์„ ํ†ตํ•ด ํ˜„์žฌ ๊ฒฝ๋กœ $(pwd)๋ฅผ nginx ์ปจํ…Œ์ด๋„ˆ ๋‚ด์— /usr/share/nginx/html์— ๋งคํ•‘ํ•ด์ฃผ์ž.

์ด ๋ชจ๋“  ๊ณผ์ •์€ ์ดํ•ดํ•  ์ˆ˜๋Š” ์žˆ์ง€๋งŒ ์‚ด์ง verboseํ•˜๋‹ค. compose๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋Ÿฐ ๋ฒˆ๊ฑฐ๋กœ์šด cli๋ฅผ ์ž‘์„ฑํ•˜์ง€ ์•Š๊ณ , 

docker-compose.yml์„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

docker run -it -p 8080:80 --rm -v $(pwd):/usr/share/nginx/html/ nginx

 

2. ์ปจํ…Œ์ด๋„ˆ ๊ฐ„ ์—ฐ๊ฒฐ์ด ์‰ฌ์›Œ์ง„๋‹ค.

 

์•„๋ž˜๋Š” postgres์™€ django-sample์ด๋ž€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์—ฐ๊ฒฐํ•œ ๊ฒƒ์ด๋‹ค.

--link ์˜ต์…˜์„ ์ฃผ์–ด์„œ django-sample ์ปจํ…Œ์ด๋„ˆ์—๊ฒŒ db๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ postgres ์ปจํ…Œ์ด๋„ˆ์˜ ์กด์žฌ๋ฅผ ์•Œ๋ฆฐ ๊ฒƒ์ด๋‹ค.

{์—ฐ๊ฒฐํ•  ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„}:{ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ์—์„œ ์ฐธ๊ณ ํ•  ์ด๋ฆ„}

์—ญ์‹œ๋‚˜ verboseํ•˜๋‹ค.

docker run --rm -d --name postgres \
  -e POSTGRES_DB=djangosample \
  -e POSTGRES_USER=sampleuser \
  -e POSTGRES_PASSWORD=samplesecret \
  postgres

docker run -d --rm \
  -p 8000:8000 \
  -e DJANGO_DB_HOST=db \
  --link postgres:db \
  django-sample

 

 

3. ํŠน์ • ์ปจํ…Œ์ด๋„ˆ๋ผ๋ฆฌ๋งŒ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€์ƒ ๋„คํŠธ์›Œํฌ ํ™˜๊ฒฝ์„ ๊ด€๋ฆฌํ•˜๋Š”๋ฐ ๋„ˆ๋ฌด ๋ช…๋ น์–ด๊ฐ€ ๊ธธ์–ด์ง„๋‹ค.

 

--network ์˜ต์…˜์„ ํ†ตํ•ด์„œ ํŠน์ • ๋„คํŠธ์›ŒํŠธ ๋‚ด์—๋งŒ ์กด์žฌํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ๋ผ๋ฆฌ๋งŒ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์–ด์ฃผ์—ˆ๋‹ค.

django2์˜ ๊ฒฝ์šฐ ํ•ด๋‹น ๋„คํŠธ์›Œํฌ ๋‚ด์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ปจํ…Œ์ด๋„ˆ์ด๊ธฐ ๋•Œ๋ฌธ์— --link๋กœ ์—ฐ๊ฒฐํ•ด๋„ ํ†ต์‹ ํ•  ์ˆ˜ ์—†๊ฒŒ ๋œ๋‹ค.

 

๋„ˆ๋ฌด verboseํ•˜๋‹ค...

// network ์ƒ์„ฑ
docker network create --driver bridge web-service

// ํ•ด๋‹น network๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
docker run --rm -d --name postgres \
  --network web-service \
  -e POSTGRES_DB=djangosample \
  -e POSTGRES_USER=sampleuser \
  -e POSTGRES_PASSWORD=samplesecret \
  postgres

docker run -d --rm --name django1 \
  --network web-service \
  -p 8000:8000 \
  -e DJANGO_DB_HOST=db \
  --link postgres:db \
  django-sample

docker run -d --rm --name django2 \
  -p 8001:8000 \
  -e DJANGO_DB_HOST=db \
  --link postgres:db \
  django-sample

 

 

๐Ÿณ docker-compose.yml

 

docker-compose๋ฅผ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•œ yml ํŒŒ์ผ์„ ๋งŒ๋“ค์ž. 

 

๊ท€์—ฌ์šด ๋„์ปค ์•„์ด์ฝ˜์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์•ž์„œ ๊ตฌ์„ฑํ•œ ๋„์ปค ๊ตฌ์„ฑ์„ ์•„๋ž˜์™€ ๊ฐ™์ด ํŒŒ์ผ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

version: '3'

volumes:
  postgres_data: {}

services:
  db:
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgres/data
    environment:
      - POSTGRES_DB=djangosample
      - POSTGRES_USER=sampleuser
      - POSTGRES_PASSWORD=samplesecret
      
  django:
    build:
      context: .
      dockerfile: ./compose/django/Dockerfile-dev
    volumes:
      - ./:/app/
    command: ["./manage.py", "runserver", "0:8000"]
    environment:
     - DJANGO_DB_HOST=db
    depends_on:
      - db
    restart: always
    ports:
      - 8000:8000

 

์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ํ•ด๋‹น docker-compose.yml์ด ์žˆ๋Š” ํŒŒ์ผ์— ๊ฐ€์„œ docker-compose up ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด -d ์˜ต์…˜๋„ ์ค์‹œ๋‹ค.

docker-compose up -d

 

์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋‚ด๋ฆฌ๊ณ  ์‹ถ๋‹ค๋ฉด downํ•ฉ์‹œ๋‹ค.

docker-compose down

 

 

๐Ÿณ docker-compose ๋ช…๋ น์–ด

 

 

docker-compose up -d // ๋„์ปค ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์‹คํ–‰
docker-compose up --force-recreate // ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์ƒˆ๋กœ ๋งŒ๋“ค๊ธฐ
docker-compose up --build // ๋„์ปค ์ด๋ฏธ์ง€ ๋นŒ๋“œ ํ›„ compose up

 

1. docker-compose up ์—์„œ --build ํ”Œ๋ž˜๊ทธ ์—ฌ๋ถ€์˜ ์ฐจ์ด๋Š”,

--build๊ฐ€ ๋ถ™์œผ๋ฉด ์บ์‹ฑ๋œ ์ด๋ฏธ์ง€๋ฅผ ์ฒดํฌํ•˜์ง€ ์•Š๊ณ  ๋ฌด์กฐ๊ฑด ๋นŒ๋“œ๋ฅผ ํ•˜๊ณ  ์‹œ์ž‘ํ•˜๋ผ๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.

๋ถ™์ด์ง€ ์•Š๊ณ  ์จ๋„ ์ด๋ฏธ์ง€์— ์—†์œผ๋ฉด ๋นŒ๋“œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. 

์†Œ์Šค ์ˆ˜์ •์ด ์ด๋ฃจ์–ด์กŒ์„ ๋•Œ๋Š” ๋‹ค์‹œ ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œํ•ด์•ผ ํ•˜๋ฏ€๋กœ ๊ฐ€๊ธ‰์  --build๋ฅผ ๋ถ™์—ฌ์„œ compose-up์„ ํ•˜๋„๋กํ•ฉ์‹œ๋‹ค.

 

2. -d (detached) ๋ชจ๋“œ๋ฅผ ๋ถ™์ด๋ฉด ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋ผ์„œ ๋‹น์—ฐํžˆ ์•ฑ ๋‚ด์˜ ์ถœ๋ ฅ์ด ํ„ฐ๋ฏธ๋„์— ์ฐํžˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

docker-compose start // ์ •์ง€ํ•œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์žฌ๊ฐœ
docker-compose start mysql // mysql ์ปจํ…Œ์ด๋„ˆ๋งŒ ์žฌ๊ฐœ

docker-compose restart // ์ด๋ฏธ ์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ๋‹ค์‹œ ์‹œ์ž‘
docker-compose restart redis // ์ด๋ฏธ ์‹คํ–‰์ค‘์ธ redis ์žฌ์‹œ์ž‘

docker-compose stop // gracefully stopํ•จ.
docker-compose stop wordpress

docker-compose down // stop ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ๊นŒ์ง€

docker-compose logs
docker-compose logs -f // ๋กœ๊ทธ watching

docker-compose ps // ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก

docker-compose exec [์ปจํ…Œ์ด๋„ˆ] [๋ช…๋ น์–ด]
docker-compose exec wordpress bash // wordpress์—์„œ bash ๋ช…๋ น์–ด ์‹คํ–‰

docker-compose build // build ๋ถ€๋ถ„์— ์ •์˜๋œ ๋Œ€๋กœ ๋นŒ๋“œ
docker-compose build wordpress // wordpess ์ปจํ…Œ์ด๋„ˆ๋งŒ ๋นŒ๋“œ

docker-compose run [service] [command] // ์ด๋ฏธ docker-compose ๊ฐ€๋™ ์ค‘์ธ ๊ฒƒ๊ณผ ๋ณ„๊ฐœ๋กœ ํ•˜๋‚˜ ๋” ์˜ฌ๋ฆด ๋•Œ
docker-compose run nginx bash

 

 

๐Ÿณ docker-compose.yml ๋ฌธ๋ฒ•

 

- version

docker-compose.yml ํŒŒ์ผ์˜ ๋ช…์„ธ ๋ฒ„์ „. ๋ฒ„์ „์— ๋”ฐ๋ผ ๋„์ปค ์—”์ง„ ๋ฒ„์ „๋„ ๋‹ค๋ฅด๋‹ค.

๋ญ ์“ธ์ง€๋Š” docs.docker.com/compose/compose-file/ ์ฐธ๊ณ .

version: '2'

 

- services 

 

์ปจํ…Œ์ด๋„ˆ์— ์‚ฌ์šฉํ•  ์ด๋ฏธ์ง€ ์ด๋ฆ„๊ณผ ํƒœ๊ทธ(๋ฒ„์ „) ํƒœ๊ทธ๋ฅผ ์ƒ๋žตํ•˜๋ฉด ์ตœ์‹  ๋ฒ„์ „์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. 

์ด๋ฏธ์ง€๊ฐ€ ์—†์œผ๋ฉด ์ž๋™์œผ๋กœ pullํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ตณ์ด ์ˆ˜์ž‘์—…์œผ๋กœ ๋กœ์ปฌ์— ์„ค์น˜ํ•  ํ•„์š” ์—†์Šต๋‹ˆ๋‹ค.

 

๋˜, ports์— ์žˆ์–ด์„œ ์ผ๋ฐ˜ dockerfile์„ ๊ตฌ์„ฑํ•  ๋•Œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ˜ธ์ŠคํŠธ ํฌํŠธ๋กœ ์ ‘๊ทผํ•ด์•ผ ๋‚ด์šฉ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

services:
  django:
    image: ...
    ports:
      - "8000:80" // ํ˜ธ์ŠคํŠธ ํฌํŠธ:์ปจํ…Œ์ด๋„ˆ ํฌํŠธ
  postgres:
  	image: ....

 

restart

์žฌ์‹œ์ž‘ ์ •์ฑ…. pm2 ๋Œ€์‹  ์‚ฌ์šฉํ•˜๊ธฐ๋„ ํ•˜๊ธฐ๋„ํ•˜๊ณ , ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‹คํ–‰๋˜๋Š” ์ˆœ๊ฐ„ ์ ‘๊ทผํ•˜์—ฌ ์ ‘๊ทผ ์‹œ๊ฐ„์— ๋”ฐ๋ฅธ ์‹คํŒจ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ณ , ์ž๋™์œผ๋กœ ์žฌ์‹œ์ž‘ํ•˜๊ฒŒ๋” ํ•ด์ฃผ๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

์—ฌ๋ž˜์ €๋ž˜ ์œ ์šฉํ•œ ๋…€์„์ž…๋‹ˆ๋‹ค.

services:
  django:
    image: ...
    restart: always // "no", always, on-failure, unless-stopped
  postgres:
  	image: ....

 

build

์ด๋ฏธ์ง€๋ฅผ ์ž์ฒด ๋นŒ๋“œ ํ›„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ build๋ฅผ ์ด์šฉํ•  ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฏธ์ง€ ๋นŒ๋“œ๋ฅผ ์œ„ํ•œ dockerfile์ด ํ•„์š”ํ•˜๋‹ˆ๊นŒ ์ง€์ •ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ž์ฒด ๋นŒ๋“œ๋‹ˆ๊นŒ image ์†์„ฑ ๋Œ€์‹  ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

docker-compose build๋ฅผ ํ†ตํ•ด์„œ ๋นŒ๋“œํ•œ ํ›„ docker-compose upํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

services:
  django:
    build:
      context: .
      dockerfile: ./compose/django/Dockerfile-dev 
  postgres:
  	image: ....

 

environment

 

์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ์ด๋ฏธ์ง€์˜ ํ™˜๊ฒฝ ๋ณ€์ˆ˜.

์—ฌ๊ธฐ์„œ, dockerfile์˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜์™€ docker-compose.yml์˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์ค‘๋ณต๋˜์–ด์„œ ์˜ฌ๋ผ๊ฐ€๋ฉด ์–ด๋–ป๊ฒŒ ๋˜๋Š๋ƒ?๋Š” ์˜๋ฌธ์ด ์ƒ๊น๋‹ˆ๋‹ค.

์šฐ์„ ์ˆœ์œ„๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ฆ‰, docker.compose.yml์ด ๋ฎ์–ด์“ฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

1. docker-compose [run / exec] -e key:value

2. docker-compose.yml์˜ environment

3. Dockerfile์˜ ENV

 

services:
  db:
    image: mysql:5.7 // ์‚ฌ์šฉํ•  ์ด๋ฏธ์ง€
    volumes:
      - ./mysql:/var/lib/mysql // ๋ณผ๋ฅจ(์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ฃฝ์–ด๋„ ๋ฐ์ดํ„ฐ๋ฅผ ์œ ์ง€)
    restart: always // ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ฃฝ์ง€ ์•Š๊ณ  ๊ณ„์†
    environment: // ํ™˜๊ฒฝ๋ณ€์ˆ˜
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

 

volumes

services:
  nginx:
    image: nginx
    ports:
      - 8080:80
    volumes:
      - ./:/usr/share/nginx/html
    link:
      - mysql:db

 

link (legacy)

docker cli ์‚ฌ์šฉํ•  ๋•Œ --link์™€ ๋™์ผํ•˜๋‹ค. {์—ฐ๊ฒฐํ•  ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„}:{ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ์—์„œ ์ฐธ๊ณ ํ•  ์ด๋ฆ„}

๊ทธ๋Ÿฌ๋‚˜ ๊ธฐ๋ณธ์ ์œผ๋กœ docker-compose ๋‚ด๋ถ€์—์„  ๋ชจ๋“  ์ปจํ„ฐ๋„ค์ด๋„ˆ๊ฐ€ ์†Œํ†ตํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ๋˜์ง€ ์•Š์Œ.

 

services:
  nginx:
    image: nginx
    ports:
      - 8080:80
    link:
      - mysql:db

 

 

depends_on

์˜์กด์„ฑ ๋ช…์‹œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์•„๋ž˜์™€ ๊ฐ™์ด ์จ ์žˆ๋‹ค๋ฉด, nginx๋Š” mysql์— ์˜์กดํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ mysql ์ด๋ฏธ์ง€๊ฐ€ ๋จผ์ € ์‹คํ–‰๋œ ํ›„์— ๊ทธ ๋‹ค์Œ์— nginx ์ด๋ฏธ์ง€๊ฐ€ ์‹คํ–‰๋œ๋‹ค.

services:
  mysql:
    image: mysql
    ...
  nginx:
    image: nginx
    ports:
      - 8080:80
    depends_on:
      - mysql

 

 

๋‹ค์–‘ํ•œ docker-compose.yml ์ž‘์„ฑ ์˜ˆ์‹œ๋“ค

 

1. ๊ฐ„๋‹จํžˆ Nginx ์˜ฌ๋ฆฌ๊ธฐ

 

docker run -it -p 8080:80 -v $(pwd):/usr/share/nginx/html nginx๋กœ ์‹คํ–‰ํ•˜๋˜ ๊ฒƒ์„ docker-compose.yml๋กœ ๋งŒ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑ๋  ์ˆ˜ ์žˆ๋‹ค. cli ํ™˜๊ฒฝ์ด ์•„๋‹ˆ๋‹ˆ๊นŒ $(pwd)๊ผด๋กœ ์‚ฌ์šฉ๋ชปํ•˜๊ณ , ์ง์ ‘ ๊ฒฝ๋กœ๋ฅผ ์ค€ ๊ฒƒ๋งŒ ๋‹ค๋ฅด๋‹ค.

version: '3'

services:
  nginx:
    image: nginx
    ports:
      - 8080:80
    volumes:
      - ./:/usr/share/nginx/html

 

 

2. ์›Œ๋“œํ”„๋ ˆ์Šค

 

mysql ์‹คํ–‰ํ•˜๋ฉด์„œ ์ฝ์–ด๋“ค์ด๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋“ค์ด ์žˆ์œผ๋‹ˆ ์•„๋ž˜์ฒ˜๋Ÿผ ์„ค์ •ํ•ด์ฃผ๊ณ ,

db๋ฅผ ๋จผ์ € ์ผœ๋„๋ก depends_on์„ wordpress์— ์„ธํŒ…ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

version: '3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: rootpwd
      MYSQL_DATABASE: databasename
      MYSQL_USER: user
      MYSQL_PASSWORD: userpwd

  wordpress:
    image: wordpress
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wp
      WORDPRESS_DB_PASSWORD: wp
      WORDPRESS_DB_NAME: wp
    depends_on:
      - db

volumes:
  db_data: {}

 

3. flask + redis ์กฐํ•ฉ

 

dockerfile๋กœ ๋นŒ๋“œํ•œ ํ›„์— compose๋กœ ์˜ฌ๋ ธ์Šต๋‹ˆ๋‹ค.

docker-compose up -d --build

 

FROM python:3.7-alpine

WORKDIR /code

ENV FLASK_APP app.py
ENV FLASK_RUN_HOST 0.0.0.0

RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .

CMD ["flask", "run"]
version: '3'

services:
  redis:
    image: redis
    ports:
      - 6379:6379
    restart: always

  flask:
    image: whateveryouwant
    build:
      context: .
      dockerfile: .
    ports:
      - 5000:5000
    depends_on:
      - redis
    restart: always

 


๋Œ“๊ธ€์„ ๋‹ฌ์•„ ์ฃผ์„ธ์š”

  1. ๊ท€์—ฌ์šด ๋„์ปค ์•„์ด์ฝ˜์—์„œ ๋นต ํ„ฐ์ง€๊ณ  ๊ฐ€์š” ใ…‹ใ…‹

darren, dev blog
๋ธ”๋กœ๊ทธ ์ด๋ฏธ์ง€ DarrenKwonDev ๋‹˜์˜ ๋ธ”๋กœ๊ทธ
VISITOR ์˜ค๋Š˜60 / ์ „์ฒด634,802