๐Ÿ’พ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ตฌ์„ฑ๋œ Docker Compose ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‚ด์—์„œ ์ปจํ…Œ์ด๋„ˆ ๊ฐ„์˜ ํ†ต์‹ ์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.


๋””ํดํŠธ ๋„คํŠธ์›ŒํฌPermalink

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

## /path/our_app ๊ฒฝ๋กœ
$ docker-compose up -d

Creating network "our_app_default" with the default driver
Creating our_app_db_1 ... done
Creating our_app_web_1 ... done

Docker Compose๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋‚ด๋ฆด ๋•Œ๋Š” ๋ฐ˜๋Œ€ ์ˆœ์„œ๋กœ ๋จผ์ € ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ข…๋ฃŒ/์ œ๊ฑฐํ•ด๋†“๊ณ  ์ œ์ผ ๋งˆ์ง€๋ง‰์— ๋„คํŠธ์›Œํฌ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

$ docker-compose down
Stopping our_app_web_1 ... done
Stopping our_app_db_1  ... done
Removing our_app_web_1 ... done
Removing our_app_db_1  ... done
Removing network our_app_default



์ปจํ…Œ์ด๋„ˆ ๊ฐ„ ํ†ต์‹ Permalink

๊ฐ™์€ ๋„คํŠธ์›Œํฌ ๊ฐ„ ํ†ต์‹ 
๊ฐ™์€ ๋„คํŠธ์›Œํฌ ์•ˆ์—์„œ ์ปจํ…Œ์ด๋„ˆ ๊ฐ„์˜ ํ†ต์‹ ์€ ํ˜ธ์ŠคํŠธ๋ช…์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ํ˜ธ์ŠคํŠธ๋ช…์„ ์ง€์ •ํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์„œ๋น„์Šค์˜ ์ด๋ฆ„์ด ํ˜ธ์ŠคํŠธ๋ช…์ด ๋ฉ๋‹ˆ๋‹ค.

$ docker-compose exec web ping db

PING db (192.168.48.2) 56(84) bytes of data.
64 bytes from our_app_db_1.our_app_default (192.168.48.2): icmp_seq=1 ttl=64 time=0.094 ms
64 bytes from our_app_db_1.our_app_default (192.168.48.2): icmp_seq=2 ttl=64 time=0.162 ms


ํ˜ธ์ถœ ์œ„์น˜์— ๋”ฐ๋ฅธ ํ†ต์‹ 
์ปจํ…Œ์ด๋„Œ ๊ฐ„ ํ†ต์‹ ์—์„œ ์ฃผ์˜ํ•  ์ ์€ ์ ‘์†ํ•˜๋Š” ์œ„์น˜๊ฐ€ ๋””ํดํŠธ ๋„คํŠธ์›Œํฌ ๋‚ด๋ถ€๋ƒ ์™ธ๋ถ€๋ƒ์— ๋”ฐ๋ผ์„œ ํฌํŠธ(port)๊ฐ€ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

services:
  web:
    build: .
    ports:
      - "8001:8000"
# ํ˜ธ์ŠคํŠธ ์ปดํ“จํ„ฐ์—์„œ web ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ ์ ‘์†
$ curl -I localhost:8001

HTTP/1.1 200 OK
Date: Fri, 05 Jun 2020 02:05:10 GMT
Server: WSGIServer/0.2 CPython/3.8.2
Content-Type: text/html
X-Frame-Options: DENY
Content-Length: 16351
X-Content-Type-Options: nosniff
# ๊ฐ™์€ ๋„คํŠธ์›Œํฌ ๋‚ด์˜ ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ์—์„œ web ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ ์ ‘์†
$ docker-compose exec alpine curl -I web:8000

HTTP/1.1 200 OK
Date: Fri, 05 Jun 2020 02:13:46 GMT
Server: WSGIServer/0.2 CPython/3.8.2
Content-Type: text/html
X-Frame-Options: DENY
Content-Length: 16351
X-Content-Type-Options: nosniff



์ปค์Šคํ…€ ๋„คํŠธ์›Œํฌ ์ถ”๊ฐ€Permalink

Docker Compose๋Š” ๋””ํดํŠธ ๋„คํŠธ์›Œํฌ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ ๋„คํŠธ์›Œํฌ๋„ ํ•„์š”์— ๋”ฐ๋ผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

services:
  web:
    build: .
    ports:
      - "8000:8000"
    networks: # ์„œ๋น„์Šค์—์„œ ์—ฐ๊ฒฐํ•  ๋„คํŠธ์›Œํฌ ์ž‘์„ฑ
      - default
      - our_net

  db:
    image: postgres
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

# ๋„คํŠธ์›Œํฌ ์ถ”๊ฐ€
networks:
  our_net:
    driver: bridge

Docker Compose๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๋ฉด ๋‘๊ฐœ์˜ ๋„คํŠธ์›Œํฌ๊ฐ€ ์ƒ์„ฑ๋˜๋Š”๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$ docker-compose up -d
Creating network "our_app_default" with the default driver
Creating network "our_app_our_net" with driver "bridge"
...

$ our_app docker network ls
NETWORK ID          NAME                   DRIVER              SCOPE
f1859120a0c3        bridge                 bridge              local
95b00551745b        host                   host                local
1f7202baa40a        none                   null                local
2682634e6535        our_app_default        bridge              local
525403b38bbe        our_app_our_net        bridge              local

our_net์€ Docker Compose ๋‚ด๋ถ€์—์„œ ์ •์˜๋œ ๋„คํŠธ์›Œํฌ ์ด๋ฏ€๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋‚ด๋ฆด ๋•Œ ๋””ํดํŠธ ๋„คํŠธ์›Œํฌ์™€ ํ•จ๊ป˜ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.

$ docker-compose down

Stopping our_app_web_1 ... done
Stopping our_app_db_1  ... done
Removing our_app_web_1 ... done
Removing our_app_db_1  ... done
Removing network our_app_default
Removing network our_app_our_net



์™ธ๋ถ€ ๋„คํŠธ์›Œํฌ ์‚ฌ์šฉPermalink

Docker Compose๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๋””ํดํŠธ ๋„คํŠธ์›Œํฌ ๋Œ€์‹ ์— ์™ธ๋ถ€์—์„œ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋†“์€ ๋‹ค๋ฅธ ๋„คํŠธ์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

our_net์ด๋ผ๋Š” ๋„คํŠธ์›Œํฌ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

$ docker network create our_net
6d791b927c8c151c45a10ac13c62f3571ecf38a90756fd2ca1c62b7d3de804e8

docker-compose.yml์—์„œ ๋„คํŠธ์›Œํฌ์˜ ์˜ต์…˜์— our_net๋„คํŠธ์›Œํฌ์— external์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

# 1๋ฒˆ ๋ฐฉ๋ฒ™
version: '3.7'

services:
  web:
    build: .
    ports:
      - "8000:8000"
    networks:
      - our_net

networks:
  our_net:
    driver: bridge
    external: true

๊ฒฝ๊ณ 
์™ธ๋ถ€์—์„œ ์ƒ์„ฑ๋œ ๋„คํŠธ์›Œํฌ์ด๋ฏ€๋กœ Docker Compose ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋‚ด๋ฆด ๋•Œ ํ•ด๋‹น ๋„คํŠธ์›Œํฌ๊ฐ€ ํ•จ๊ป˜ ์‚ญ์ œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

$ docker-compose down

Stopping our_app_web_1 ... done
Stopping our_app_db_1  ... done
Removing our_app_web_1 ... done
Removing our_app_db_1  ... done
Network our_net is external, skipping

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

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

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