Docker Compose๋, ์ฌ๋ฌ๊ฐ์ ์ปจํ
์ด๋๋ฅผ ์ ์ํ๊ณ ์คํํ๊ธฐ ์ํ ๋๊ตฌ์
๋๋ค.
์ฆ, ํ๋ฒ์ 2๊ฐ ์ด์ ์ปจํ
์ด๋๋ฅผ ํ๋์ ์ธํธ์ฒ๋ผ ์คํํด์ผ ํ๋ค๋ฉด Docker Compose๋ฅผ ์ฌ์ฉํด๋ณผ ์ ์์ต๋๋ค.
๋ง๋ณด๊ธฐ๋ก ํ๋ฒ ์งํ ํด๋ด ์๋ค!
๐ณ step 1. Compose ์ค์น
๋์ปค ์ค์น ๋ช
๋ น์ด๋ถํฐ ๋น ๋ฅด๊ฒ ๋ค์ ๋ณด๊ฒ ์ต๋๋ค.
๊ณต์ํํ์ด์ง์์๋ ํ์ธํ ์ ์์ต๋๋ค.
1. Docker ์ค์น
Docker๊ฐ ์ค์น๋ OS๋ฅผ ํ์ธํฉ๋๋ค. ์ ๋ Centos7 ์ ์ค์นํฉ๋๋ค :)
[root@master /]# rpm -qa | grep release
centos-release-7-8.2003.0.el7.centos.x86_64
yum-utils ๋ฅผ ์ค์นํฉ๋๋ค.
[root@master /]# yum install -y yum-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: d36uatko69830t.cloudfront.net
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
๋์ปค ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ์ถ๊ฐํฉ๋๋ค.
[root@master /]# yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
์ด์ docker-ce, docker-ce-cli, containerd ๋ฅผ ์ค์นํฉ๋๋ค.
[root@master /]# yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
.. ์๋ต ..
Installed:
containerd.io.x86_64 0:1.3.7-3.1.el7 docker-ce.x86_64 3:19.03.13-3.el7
docker-ce-cli.x86_64 1:19.03.13-3.el7
Dependency Installed:
container-selinux.noarch 2:2.119.2-1.911c772.el7_8
Complete!
docker ์ค์น๊ฐ ์๋ฃ๋์๋ค๋ฉด, docker ๋ฐ๋ชฌ์ ์์ํฉ๋๋ค.
[root@master /]# systemctl start docker
[root@master /]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
2. Docker Compose ์ค์น
docker Compose์ ๋ค์ด๋ฐ์ต๋๋ค.
[root@master /]# sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 651 100 651 0 0 1273 0 --:--:-- --:--:-- --:--:-- 1273
100 11.6M 100 11.6M 0 0 3077k 0 0:00:03 0:00:03 --:--:-- 5060k
๋ฐ์ด๋๋ฆฌํ์ผ์ ์คํ ๊ถํ์ ์ฃผ๊ณ , ์ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ์์ฑํ์ฌ ๋ช ๋ น์ด์ฒ๋ผ ์ฌ์ฉํ ์ ์๋๋ก ํฉ๋๋ค.
[root@master /]# sudo chmod +x /usr/local/bin/docker-compose
[root@master /]# sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose ๋ช ๋ น์ด๊ฐ ์ ๋์ํ๋์ง ํ์ธํ๊ธฐ ์ํด์ ์๋์ฒ๋ผ ๋ฒ์ ์ ํ์ธํด๋ด ์๋ค.
[root@master /]# docker-compose --version
docker-compose version 1.27.4, build 40524192
๐ณ step2. Compose ์์ํ๊ธฐ
์, ์ด์ ํ
์คํธ ํ์ผ์ ์ด์ฉํ์ฌ ๋์ปค ์ปดํฌ์ฆ๋ฅผ ์ฌ์ฉํด๋ณด๊ฒ ์ต๋๋ค.
๋ชจ๋ ๋ด์ฉ์ ๋์ปค ๊ณต์ํํ์ด์ง์ ์ด๋ฏธ ๋์์๋ ๋ด์ฉ์
๋๋ค.
1. ๊ธฐ๋ณธ ์ค์
๋จผ์ , ํ ์คํธ๋ฅผ ์งํํ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํ๊ณ . ๊ทธ ์์ ํ ์คํธ ์ดํ๋ฆฌ์ผ์ด์ ์์ ๋ฃจํธ๋๋ ํ ๋ฆฌ๋ก ์ฌ์ฉ๋ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
[root@master /]# mkdir Docker && cd Docker
[root@master Docker]# mkdir compose_test && cd compose_test/
2. Application ์์ฑ
๋จผ์ , app.py ํ์ผ์ ์์ฑํฉ๋๋ค. ๋ณต์ฌ ๋ถ์ฌ๋ฃ๊ธฐ ํ์ธ์.
[root@master /]# vim Docker/compose_test/app.py
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
๋๋ฒ์งธ๋ก, requirements.txt ํ์ผ์ ์์ฑํฉ๋๋ค.
[root@master compose_test]# vim requirements.txt
flask
redis
3. Dockerfile ์์ฑ
์ด๋ฒ์๋, Dockerfile์ ์์ฑํฉ๋๋ค.
Dockerfile ์ด๋, ์ด ์ ํฌ์คํ
์์ ๋ค๋ฃจ์๋ ๋ด์ฉ์ผ๋ก, Docker์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๋๋ฐ ํ์ํ ๋ ์ํผ๊ฐ ์ ํ ํ์ผ์
๋๋ค.
[root@master compose_test]# vim Dockerfile
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
EXPOSE 5000
COPY . .
CMD ["flask", "run"]
๊ฐ ๋ด์ฉ์ ์๋์ ๊ฐ์ต๋๋ค.
- Python 3.7 ์ด๋ฏธ์ง๋ก ์์ํ๋ ์ด๋ฏธ์ง๋ฅผ ๋น๋ํฉ๋๋ค.
- ์์ ๋๋ ํ ๋ฆฌ๋ฅผ๋ก ์ค์ ํ์ญ์์ค /code.
- flask๋ช ๋ น์ ์ฌ์ฉ๋๋ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํฉ๋๋ค .
- gcc ๋ฐ ๊ธฐํ ์ข ์์ฑ ์ค์น
- requirements.txtPython ์ข ์์ฑ์ ๋ณต์ฌ ํ๊ณ ์ค์นํฉ๋๋ค.
- ์ด๋ฏธ์ง์ ๋ฉํ ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ์ฌ ์ปจํ ์ด๋๊ฐ ํฌํธ 5000์์ ์์ ์ค์์ ์ค๋ช ํฉ๋๋ค.
- .ํ๋ก์ ํธ ์ ํ์ฌ ๋๋ ํ ๋ฆฌ ๋ฅผ .์ด๋ฏธ์ง ์ workdir ์ ๋ณต์ฌํ์ญ์์ค .
- ์ปจํ ์ด๋์ ๊ธฐ๋ณธ ๋ช ๋ น์ flask run.
4 . docker-compose.yml ํ์ผ ์์ฑ
docker-compose.yml ์ ์์ฑํฉ๋๋ค.
[root@master compose_test]# vim docker-compose.yml
version: "3.8"
services:
web:
build: .
ports:
- "5000:5000"
redis:
image: "redis:alpine"
๊ฐ ๋ด์ฉ์ ์๋์ ๊ฐ์ต๋๋ค.
- version:
- services: ์คํํ ์ปจํ ์ด๋ ๋ชฉ๋ก์ ๋๋ค.
- web ์๋น์ค (์ปจํ ์ด๋)๋ ํ์ฌ ๋๋ ํ ๋ฆฌ์ ์๋ Dockerfile๋ก ๋น๋๋ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ๋ฉฐ, ํฌํธ๋ฅผ ๋ฐ์ธ๋ฉ ํฉ๋๋ค (5000:5000)
- redis ์๋น์ค๋ Redis ๊ณต๊ฐ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํฉ๋๋ค.
์, ์ด์ 4๊ฐ์ ํ์ผ์ ๋ชจ๋ ์์ฑํ์์ต๋๋ค.
tree ๋ช
๋ น์ด๋ฅผ ์ด์ฉํด์ ๋ณด๋ฉด ์ด๋ฐ ๊ฒฐ๊ณผ๊ฐ ๋ณด์ผ๊ฒ๋๋ค. ๋ง๋ค๋ ๋์๋ฌธ์/์คํ์ ์ฃผ์ํ์ธ์.
[root@master /]# tree /Docker/compose_test/
/Docker/compose_test/
โโโ Dockerfile
โโโ app.py
โโโ docker-compose.yml
โโโ requirements.txt
5 . Compose๋ก ์ดํ๋ฆฌ์ผ์ด์ ์คํ
์ด์ , ๋๋ง์ ๋์ปค ์ปดํฌ์ฆ ์ ! ์ ๋๋ค.
[root@master compose_test]# docker-compose up
Creating network "compose_test_default" with the default driver
Building web
Step 1/10 : FROM python:3.7-alpine
3.7-alpine: Pulling from library/python
df20fa9351a1: Pull complete
36b3adc4ff6f: Pull complete
4db9de03f499: Pull complete
cd38a04a61f4: Pull complete
9a3838385f13: Pull complete
Digest: sha256:9fbee97d521b846689f4dbf0d5f2770c734d4a09e6d0a0991efc916c58970e99
Status: Downloaded newer image for python:3.7-alpine
---> 295b051ee125
Step 2/10 : WORKDIR /code
---> Running in 6699ada8855b
Removing intermediate container 6699ada8855b
---> 9740cfe088f6
Step 3/10 : ENV FLASK_APP=app.py
---> Running in a837433ea544
Removing intermediate container a837433ea544
---> dc1486d931c3
Step 4/10 : ENV FLASK_RUN_HOST=0.0.0.0
---> Running in f18e93d7fddf
Removing intermediate container f18e93d7fddf
---> ff9b48cde18c
Step 5/10 : RUN apk add --no-cache gcc musl-dev linux-headers
---> Running in 121818e10c32
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/13) Installing libgcc (9.3.0-r2)
(2/13) Installing libstdc++ (9.3.0-r2)
(3/13) Installing binutils (2.34-r1)
(4/13) Installing gmp (6.2.0-r0)
(5/13) Installing isl (0.18-r0)
(6/13) Installing libgomp (9.3.0-r2)
(7/13) Installing libatomic (9.3.0-r2)
(8/13) Installing libgphobos (9.3.0-r2)
(9/13) Installing mpfr4 (4.0.2-r4)
(10/13) Installing mpc1 (1.1.0-r1)
(11/13) Installing gcc (9.3.0-r2)
(12/13) Installing linux-headers (5.4.5-r1)
(13/13) Installing musl-dev (1.1.24-r9)
Executing busybox-1.31.1-r16.trigger
OK: 153 MiB in 48 packages
Removing intermediate container 121818e10c32
---> 6dc320445e5f
Step 6/10 : COPY requirements.txt requirements.txt
---> 891a41cc48a5
Step 7/10 : RUN pip install -r requirements.txt
---> Running in 6ed6c7af768b
Collecting flask
Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting redis
Downloading redis-3.5.3-py2.py3-none-any.whl (72 kB)
Collecting click>=5.1
Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting itsdangerous>=0.24
Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting Jinja2>=2.10.1
Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
Collecting Werkzeug>=0.15
Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
Collecting MarkupSafe>=0.23
Downloading MarkupSafe-1.1.1.tar.gz (19 kB)
Building wheels for collected packages: MarkupSafe
Building wheel for MarkupSafe (setup.py): started
Building wheel for MarkupSafe (setup.py): finished with status 'done'
Created wheel for MarkupSafe: filename=MarkupSafe-1.1.1-cp37-cp37m-linux_x86_64.whl size=16913 sha256=fdfbd33f72c6753a24891ac61ed9448a83ca12b7f11fc2248164388cf0dea9ea
Stored in directory: /root/.cache/pip/wheels/b9/d9/ae/63bf9056b0a22b13ade9f6b9e08187c1bb71c47ef21a8c9924
Successfully built MarkupSafe
Installing collected packages: click, itsdangerous, MarkupSafe, Jinja2, Werkzeug, flask, redis
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.2 itsdangerous-1.1.0 redis-3.5.3
Removing intermediate container 6ed6c7af768b
---> da6859d6dc07
Step 8/10 : EXPOSE 5000
---> Running in 856d2ddff942
Removing intermediate container 856d2ddff942
---> ccc506260293
Step 9/10 : COPY . .
---> c336b88dd79c
Step 10/10 : CMD ["flask", "run"]
---> Running in b67224eaff17
Removing intermediate container b67224eaff17
---> 2a0a01a5be7b
Successfully built 2a0a01a5be7b
Successfully tagged compose_test_web:latest
์ด๋ฏธ์ง๋ ์ด๋ค๊ฒ์ด ์๋์ง, ์ปจํ
์ด๋๋ ์ ๋์ํ๋์ง ํ์ธํด๋ณด๊ฒ ์ต๋๋ค.
ํฐ๋ฏธ๋ ์ฐฝ์ ํ๋ ์ผ์ ์๋ ๋ช
๋ น์ด๋ก ์ ๋์ํ๊ณ ์๋์ง ํ์ธํ๊ฒ ์ต๋๋ค. :)
๋จผ์ ์ด๋ฏธ์ง๋ฅผ ํ์ธํด๋ด ๋๋ค.
[root@master compose_test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
compose_test_web latest 2a0a01a5be7b 14 minutes ago 196MB
redis alpine bd71e6db4a54 3 weeks ago 32.2MB
python 3.7-alpine 295b051ee125 3 weeks ago 41.7MB
์ด์ ์ปจํ ์ด๋ ๋ชฉ๋ก์ ํ์ธํด๋ด ๋๋ค.
[root@master compose_test]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
18012056d099 compose_test_web "flask run" 14 minutes ago Up 14 minutes 0.0.0.0:5000->5000/tcp compose_test_web_1
05f968a0fc78 redis:alpine "docker-entrypoint.s…" 14 minutes ago Up 14 minutes 6379/tcp compose_test_redis_1
์น๋ธ๋ผ์ฐ์ ์์๋ ์ ๋์ํ๋ค์ ;)
6 . Compose ํ์ผ ์์ ํด๋ณด๊ธฐ
์ด๋ฒ์๋, docker-compose.ymlํ์ผ์ ์์ ํด๋ณด๊ฒ ์ต๋๋ค. 9~12์ค์ ๋ณต์ฌ ๋ถ์ฌ๋ฃ๊ธฐ ํ์ธ์ :)
[root@master compose_test]# vim docker-compose.yml
version: "3.8"
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
environment:
FLASK_ENV: development
redis:
image: "redis:alpine"
๊ฐ ๋ด์ฉ์ ์๋์ ๊ฐ์ต๋๋ค.
- volumes์ ํธ์คํธ์ ํ์ฌ ๋๋ ํ ๋ฆฌ๋ฅผ ์ปจํ ์ด๋์ /code ๋๋ ํ ๋ฆฌ์ ๋ง์ดํธํ์ฌ ์ฌ์ฉํ๊ฒ ๋ค๋ ๋ป์ ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์ด๋ฏธ์ง๋ฅผ ๋ค์ ๋น๋ํ์ง ์๊ณ ๋ ์ฝ๋๋ฅผ ์ฆ์ ์์ ํ ์ ์์ต๋๋ค.
- envirenment๋ FLASK_ENV ํ๊ฒฝ๋ณ์๋ฅผ ์ง์ ํฉ๋๋ค. ๊ฐ๋ฐ์ ๋ชจ๋์์ ์คํํ๋ฉฐ, ๊ฐ๋ฐ์์๋ง ์ฌ์ฉํ๋๋ก ํฉ๋๋ค.
์์ง, ์ปจํ ์ด๋๊ฐ ์คํ์ค์ด๋ผ๋ฉด ctrl+C ๋ฅผ ๋๋ฌ ํ๋ก์ธ์ค๋ฅผ ์ข ๋ฃํ๊ณ ๋ค์ํ๋ฒ docker-compose up์ ์คํํฉ๋๋ค.
[root@master compose_test]# docker-compose up
Recreating compose_test_web_1 ... done
Starting compose_test_redis_1 ... done
Attaching to compose_test_redis_1, compose_test_web_1
redis_1 | 1:C 05 Oct 2020 02:49:34.173 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 05 Oct 2020 02:49:34.173 # Redis version=6.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 05 Oct 2020 02:49:34.173 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 05 Oct 2020 02:49:34.175 * Running mode=standalone, port=6379.
redis_1 | 1:M 05 Oct 2020 02:49:34.175 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 05 Oct 2020 02:49:34.175 # Server initialized
redis_1 | 1:M 05 Oct 2020 02:49:34.176 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1 | 1:M 05 Oct 2020 02:49:34.176 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled (set to 'madvise' or 'never').
redis_1 | 1:M 05 Oct 2020 02:49:34.176 * Loading RDB produced by version 6.0.8
redis_1 | 1:M 05 Oct 2020 02:49:34.176 * RDB age 32 seconds
redis_1 | 1:M 05 Oct 2020 02:49:34.176 * RDB memory usage when created 0.79 Mb
redis_1 | 1:M 05 Oct 2020 02:49:34.176 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 05 Oct 2020 02:49:34.176 * Ready to accept connections
web_1 | * Serving Flask app "app.py" (lazy loading)
web_1 | * Environment: development
web_1 | * Debug mode: on
web_1 | * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
web_1 | * Restarting with stat
web_1 | * Debugger is active!
web_1 | * Debugger PIN: 171-548-060
7 . Application ์์ ํ๊ธฐ
ํธ์คํธ์ ๋๋ ํ ๋ฆฌ์ ์ปจํ
์ด๋์ /code ๋๋ ํ ๋ฆฌ๊ฐ ๊ณต์ ๋์์ผ๋ฏ๋ก, ์ด๋ฏธ์ง๋ฅผ ๋ค์ ๋น๋ํ์ง ์๊ณ ๋ ์ฝ๋๋ฅผ ์์ ํ ์ ์์ต๋๋ค.
app.py๋ฅผ ์์ ํ์ฌ ํ์ธํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. (๋งจ ๋ง์ง๋ง ํ์ค๋ง ๋ฐ๋์์ต๋๋ค)
[root@master compose_test]# vim app.py
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
# return 'Hello World! I have been seen {} times.\n'.format(count)
return 'Hello Docker?! I have been seen {} times.\n'.format(count)
๋ค์ ๋น๋ํ ํ์์์ด, ์ ๋ง ์ฝ๋๊ฐ ๋ฐ๋ก ๋ฐ์์ด ๋์ต๋๋ค.
8 . ๋ค๋ฅธ ๋ช ๋ น์ด ์ฌ์ฉํด๋ณด๊ธฐ
๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํํ๊ธฐ์ํด์ -d ์ต์ ์ ๋ฃ์ด ์คํํ๊ณ , docker-compose ps ๋ช ๋ น์ผ๋ก ์ํ๋ฅผ ํ์ธํด๋ณผ ์ ์์ต๋๋ค.
[root@master compose_test]# docker-compose up -d
Starting compose_test_web_1 ... done
Starting compose_test_redis_1 ... done
์ ๋์ํ๋์ง ํ์ธํค๋ด ์๋ค.
[root@master compose_test]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------
compose_test_redis_1 docker-entrypoint.sh redis ... Up 6379/tcp
compose_test_web_1 flask run Up 0.0.0.0:5000->5000/tcp
docker-compose run ๋ช
๋ น์ด๋ ์๋น์ค์ ๋ํ ์ผํ์ฑ ๋ช
๋ น์ ์คํํ ์ ์์ต๋๋ค.
์๋ฅผ๋ค์ด docker-compuse run web env ๋ช
๋ น์ผ๋ก web์๋น์ค์์ ์ฌ์ฉํ ์ ์๋ ํ๊ฒฝ๋ณ์๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
[root@master compose_test]# docker-compose run web env
Creating compose_test_web_run ... done
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=6ff69d334701
TERM=xterm
FLASK_ENV=development
LANG=C.UTF-8
GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
PYTHON_VERSION=3.7.9
PYTHON_PIP_VERSION=20.2.3
PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/fa7dc83944936bf09a0e4cb5d5ec852c0d256599/get-pip.py
PYTHON_GET_PIP_SHA256=6e0bb0a2c2533361d7f297ed547237caf1b7507f197835974c0dd7eba998c53c
FLASK_APP=app.py
FLASK_RUN_HOST=0.0.0.0
HOME=/root
docker-compose stop ๋ช
๋ น์ด๋ ํ์ฌ compose๋ก ์ด์์ค์ธ ์ปจํ
์ด๋๋ฅผ ์ค์งํฉ๋๋ค.
์ค์งํด๋ด
์๋ค :)
[root@master compose_test]# docker-compose stop
Stopping compose_test_web_1 ... done
Stopping compose_test_redis_1 ... done
์ปจํ ์ด๋์ ์ํ๋ฅผ ํ์ธํด๋ณด๋ฉด Exited ์ ๋๋ค.
[root@master compose_test]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6ff69d334701 compose_test_web "env" 42 minutes ago Exited (0) 42 minutes ago compose_test_web_run_e394dfbcb003
9739bd2f069d compose_test_web "flask run" 58 minutes ago Exited (0) 26 seconds ago compose_test_web_1
05f968a0fc78 redis:alpine "docker-entrypoint.s…" 2 hours ago Exited (0) 26 seconds ago compose_test_redis_1
docker-compose down ๋ช ๋ น์ด๋ ๋ชจ๋ ์ปจํ ์ด๋๋ฅผ ์ค๋จํ๊ณ ์ญ์ ํฉ๋๋ค. --volumes ์ต์ ์ ์ฌ์ฉํ๋ฉด ๋์ปค ๋ณผ๋ฅจ๋ ํจ๊ป ์ญ์ ๋ฉ๋๋ค.
[root@master compose_test]# docker-compose down --volumes
Removing compose_test_web_run_e394dfbcb003 ... done
Removing compose_test_web_1 ... done
Removing compose_test_redis_1 ... done
Removing network compose_test_default
์ปจํ ์ด๋ ๋ชฉ๋ก์ ํ์ธํด๋ณด๋ ์ ๋ถ ์ ์ง์์ก๋ค์ :)
[root@master compose_test]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
์ด๋ฒ ํฌ์คํ
์ ์ฌ๊ธฐ๊น์ง ์
๋๋ค.
๊ณ ์ํ์
จ์ต๋๋ค. ๐๐๐ ๋ฟ
โญ๏ธ
์ฐธ์กฐ ๋งํฌ
www.44bits.io/ko/post/almost-perfect-development-environment-with-docker-and-docker-compose
docs.docker.com/compose/