νμΊμ€νΈ λλ³Έμ λ²μμ μμ μΆμμ λλΉνμ¬ μ€λΉλμμ΅λλ€.

Docker Composeλ μμ
νκ²½μ λ§λλ λ° λλΌμ΄ λꡬμ
λλ€.
μ ν리μΌμ΄μ
μμ μ¬μ©λλ μ€νμ λν νκ²½μ
λλ€. μ΄λ₯Ό ν΅ν΄ λ€μμ μ μν μ μμ΅λλ€.
κ·νμ μ ν리μΌμ΄μ
μ κ° κ΅¬μ± μμλ λͺ
ννκ³ κ°λ¨ν ꡬ문μ λ°λ¦
λλ€. .
μ μΆνμΌλ‘ μ΄λ¬ν YAML νμΌμ μμ
μ νλ‘λμ
μμ μ§μ μ¬μ©ν μ μμ΅λλ€.
무리 .
νμ§λ§ μ΄κ²μ λμΌν docker-compose νμΌμ μ¬μ©ν μ μλ€λ κ²μ μλ―Έν©λκΉ?
κ°λ° νκ²½κ³Ό νλ‘λμ
νκ²½μμ λͺ¨λ μ¬μ©ν μ μλμ? μλλ©΄ κ°μ νμΌμ μ¬μ©νμΈμ.
μ€ν
μ΄μ§μ΄μ? μ, μΌλ°μ μΌλ‘λ κ·Έλ μ΅λλ€. νμ§λ§ μ΄λ¬ν κΈ°λ₯μ μ¬μ©νλ €λ©΄ λ€μμ΄ νμν©λλ€.
- λ³μ 보κ°: μΌλΆ νκ²½ λ³μ μ¬μ©
κ° νκ²½λ§λ€ λ³ννλ κ°μΉ. - κ΅¬μ± μ¬μ μ: λ λ²μ§Έ(λλ λͺ¨λ )λ₯Ό μ μνλ κΈ°λ₯
μλμ μΌλ‘ 무μΈκ°λ₯Ό λ³κ²½ν λ λ€λ₯Έ νμ docker-compose νμΌ
λ¨Όμ , docker composeκ° λ νμΌμ λ³ν©ν©λλ€.
κ°λ° νμΌκ³Ό νλ‘λμ νμΌμ μ°¨μ΄μ
κ°λ° μ€μ μ½λ λ³κ²½ μ¬νμ 체ν¬μΈνκ³ μΆμ κ°λ₯μ±μ΄ κ°μ₯ λμ΅λλ€.
μ€μκ° λͺ¨λ. μ΄λ₯Ό μν΄ μμ€ μ½λ λ³Όλ₯¨μ μΌλ°μ μΌλ‘
μ ν리μΌμ΄μ
μ λ°νμμ ν¬ν¨νλ 컨ν
μ΄λμ
λλ€. νμ§λ§ νλ‘λμ
νκ²½μ κ²½μ°
μ΄ λ°©λ²μ μ ν©νμ§ μμ΅λλ€.
μμ°μμλ μ¬λ¬ λ
Έλκ° μλ ν΄λ¬μ€ν°κ° μκ³ λ³Όλ₯¨μ λ‘컬μ
λλ€.
컨ν
μ΄λ(λλ μλΉμ€)κ° μ€ν μ€μΈ λ
Έλλ₯Ό κΈ°μ€μΌλ‘ νλ―λ‘
볡μ‘ν μμ
μμ΄ μμ€ μ½λλ₯Ό λ§μ΄νΈν μ μμ΅λλ€.
μ½λ λκΈ°ν, μ νΈ λ±
λμ , μ°λ¦¬λ μΌλ°μ μΌλ‘ νΉμ λ²μ μ μ½λλ₯Ό μ¬μ©νμ¬ μ΄λ―Έμ§λ₯Ό λ§λ€κ³ μΆμ΄ν©λλ€.
μ μ ν νκ·Έλ‘ νμνλ κ²μ΄ μΌλ°μ μ
λλ€(μλ―Έμ νκ·Έλ₯Ό μ¬μ©ν μ μμ)
λ²μ κ΄λ¦¬ λλ κ·νμ μ¬λμ λ°λ₯Έ λ€λ₯Έ μμ€ν
).
κ΅¬μ± μ¬μ μ
μ°¨μ΄μ μ κ³ λ €νκ³ μλ리μ€μ λ°λΌ μ’
μμ±μ΄ λ€λ₯Ό μ μμ΅λλ€.
κ°λ°κ³Ό μ΄μμμλ μλ‘ λ€λ₯Έ κ΅¬μ± νμΌμ΄ νμνλ€λ κ²μ΄ λΆλͺ
ν©λλ€.
Docker Composeλ λ€μν Compose νμΌμ κ²°ν©νλ κ²μ μ§μν©λλ€.
μ΅μ’
ꡬμ±μ μ»μ΅λλ€. μλ λ°©μμ λ€μ μμμμ νμΈν μ μμ΅λλ€.
$ cat docker-compose.yml
version: "3.2"
services:
whale:
image: docker/whalesay
command: ["cowsay", "hello!"]
$ docker-compose up
Creating network "composeconfigs_default" with the default driver
Starting composeconfigs_whale_1
Attaching to composeconfigs_whale_1
whale_1 | ________
whale_1 | < hello! >
whale_1 | --------
whale_1 |
whale_1 |
whale_1 |
whale_1 | ## .
whale_1 | ## ## ## ==
whale_1 | ## ## ## ## ===
whale_1 | /""""""""""""""""___/ ===
whale_1 | ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
whale_1 | ______ o __/
whale_1 | __/
whale_1 | __________/
composeconfigs_whale_1 exited with code 0μμ μΈκΈνλ―μ΄ docker composeλ μ¬λ¬ composeλ₯Ό κ²°ν©νλ κ²μ μ§μν©λλ€.
νμΌμ μ¬μ©νλ©΄ λ λ²μ§Έ νμΌμ λ€μν λ§€κ°λ³μλ₯Ό μ¬μ μν μ μμ΅λλ€. μ:
$ cat docker-compose.second.yml
version: "3.2"
services:
whale:
command: ["cowsay", "bye!"]
$ docker-compose -f docker-compose.yml -f docker-compose.second.yml up
Creating composeconfigs_whale_1
Attaching to composeconfigs_whale_1
whale_1 | ______
whale_1 | < bye! >
whale_1 | ------
whale_1 |
whale_1 |
whale_1 |
whale_1 | ## .
whale_1 | ## ## ## ==
whale_1 | ## ## ## ## ===
whale_1 | /""""""""""""""""___/ ===
whale_1 | ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
whale_1 | ______ o __/
whale_1 | __/
whale_1 | __________/
composeconfigs_whale_1 exited with code 0μ΄ κ΅¬λ¬Έμ κ°λ° μ€μ λͺ
λ Ήμ μ¬μ©ν λ λ§€μ° νΈλ¦¬νμ§ μμ΅λλ€.
μ¬λ¬ λ² ν΄μΌ ν κ²μ
λλ€.
λ€ννλ docker composeλ μλμΌλ‘ λ€μκ³Ό κ°μ νΉμ νμΌμ μ°Ύμ΅λλ€.
docker-compose.override.yml κ°μ μ¬μ μνλ €λ©΄ docker-compose.yml. λ§μ½
λ λ²μ§Έ νμΌμ μ΄λ¦μ λ°κΎΈλ©΄ μλ λͺ
λ Ήλ§ μ¬μ©νμ λμ λμΌν κ²°κ³Όλ₯Ό μ»μ μ μμ΅λλ€.
$ mv docker-compose.second.yml docker-compose.override.yml
$ docker-compose up
Starting composeconfigs_whale_1
Attaching to composeconfigs_whale_1
whale_1 | ______
whale_1 | < bye! >
whale_1 | ------
whale_1 |
whale_1 |
whale_1 |
whale_1 | ## .
whale_1 | ## ## ## ==
whale_1 | ## ## ## ## ===
whale_1 | /""""""""""""""""___/ ===
whale_1 | ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
whale_1 | ______ o __/
whale_1 | __/
whale_1 | __________/
composeconfigs_whale_1 exited with code 0μκ² μ΅λλ€. κ·Έλ¬λ©΄ κΈ°μ΅νκΈ°κ° λ μ¬μμ§κ² λ€μ.
λ³μμ 보κ°
κ΅¬μ± νμΌ μ§μ κΈ°λ³Έκ°μ μ¬μ©ν μ μμ΅λλ€. μ¦, λ€μμ μνν μ μμ΅λλ€.
services:
my-service:
build:
context: .
image: private.registry.mine/my-stack/my-service:${MY_SERVICE_VERSION:-latest}
...κ·Έλ¦¬κ³ λ§μ½ λΉμ μ΄ κ·Έλ κ² νλ€λ©΄ docker-compose λΉλ(λλ νΈμ) νκ²½ λ³μ μμ΄
λ΄ μλΉμ€ λ²μ , κ°μ΄ μ¬μ©λ©λλ€ μ΅κ·Ό, νμ§λ§ μ€μΉνλ©΄
λΉλ μ νκ²½ λ³μμ κ°μ λΉλ λλ νΈμ μ€μ μ¬μ©λ©λλ€.
λ±λ‘λΆμ κ°μΈ λ μ§μ€νΈλ¦¬ κ΄μ°.
λ΄ μμΉ
λμκ² νΈλ¦¬ν μ κ·Ό λ°©μμ΄ μ¬λ¬λΆμκ²λ μ μ©ν μ μμ΅λλ€. λλ λ€μ μ¬νμ λ°λ¦
λλ€.
κ°λ¨ν κ·μΉ:
- μμ°, κ°λ°(λλ κΈ°ν νκ²½)μ μν λͺ¨λ μ€νμ λ€μμ ν΅ν΄ μ μλ©λλ€.
docker-compose νμΌ. - λ΄ λͺ¨λ νκ²½μ ν¬κ΄νλ λ° νμν κ΅¬μ± νμΌμ λ€μκ³Ό κ°μ΅λλ€.
μ€λ³΅μ νΌνμΈμ. - λͺ¨λ νκ²½μμ μλνλ €λ©΄ κ°λ¨ν λͺ λ Ή νλκ° νμν©λλ€.
- μ£Όμ ꡬμ±μ νμΌμ μ μλμ΄ μμ΅λλ€. docker-compose.yml.
- νκ²½ λ³μλ μ΄λ―Έμ§ νκ·Έλ κΈ°νλ₯Ό μ μνλ λ° μ¬μ©λ©λλ€.
νκ²½λ§λ€ λ³κ²½λ μ μλ λ³μ(μ€ν μ΄μ§, ν΅ν©,
μμ°). - μμ° λ³μ κ°μ κ°μΌλ‘ μ¬μ©λ©λλ€.
κΈ°λ³Έμ μΌλ‘ μ΄κ²μ νλ‘λμ μμ μ€νμ μ€νν κ²½μ° μνμ μ΅μνν©λλ€.
νκ²½ λ³μλ₯Ό μ€μ ν©λλ€. - νλ‘λμ νκ²½μμ μλΉμ€λ₯Ό μμνλ €λ©΄ λ€μ λͺ λ Ήμ μ¬μ©νμΈμ. docker stack λ°°ν¬ β docker-compose.yml βwith-registry-auth my-stack-name μμ± νμΌ.
- μμ νκ²½μ λ€μ λͺ λ Ήμ μ¬μ©νμ¬ μμλ©λλ€. λ컀 - μλ‘ κ΅¬μ± dd.
κ°λ¨ν μλ₯Ό μ΄ν΄λ³΄κ² μ΅λλ€.
# docker-compose.yml
...
services:
my-service:
build:
context: .
image: private.registry.mine/my-stack/my-service:${MY_SERVICE_VERSION:-latest}
environment:
API_ENDPOINT: ${API_ENDPOINT:-https://production.my-api.com}
...Π
# docker-compose.override.yml
...
services:
my-service:
ports: # This is needed for development!
- 80:80
environment:
API_ENDPOINT: https://devel.my-api.com
volumes:
- ./:/project/src
...λλ μ¬μ©ν μ μμ΅λλ€ docker-compose(docker-compose up)μ€νμ μμνλ €λ©΄
μμ€ μ½λκ° λ§μ΄νΈλ κ°λ° λͺ¨λ /νλ‘μ νΈ/μμ€.
νλ‘λμ
μμλ λμΌν νμΌμ μ¬μ©ν μ μμ΅λλ€! κ·Έλ¦¬κ³ μ νν
κ°μ νμΌ docker-compose.yml μ€ν
μ΄μ§μ μν΄. μ΄κ²μ λ°°ν¬νλ €λ©΄
μ μμ μν΄μλ 미리 μ μλ νκ·Έλ‘ μ΄λ―Έμ§λ₯Ό λΉλνκ³ μ μ‘νκΈ°λ§ νλ©΄ λ©λλ€.
CI λ¨κ³μμ:
export MY_SERVICE_VERSION=1.2.3
docker-compose -f docker-compose.yml build
docker-compose -f docker-compose.yml pushμ΄μ νκ²½μμλ λ€μ λͺ λ Ήμ μ¬μ©νμ¬ μ€νν μ μμ΅λλ€.
export MY_SERVICE_VERSION=1.2.3
docker stack deploy my-stack --compose-file docker-compose.yml --with-registry-authκ·Έλ¦¬κ³ λ¬΄λμμλ κ°μ κ²μ νκ³ μΆλ€λ©΄ μ μλ§ νλ©΄ λ©λλ€.
μ€ν
μ΄μ§ νκ²½μμ μμ
νλ λ° νμν νκ²½ λ³μ:
export MY_SERVICE_VERSION=1.2.3
export API_ENDPOINT=http://staging.my-api.com
docker stack deploy my-stack --compose-file docker-compose.yml --with-registry-authμ°λ¦¬λ λ κ°μ λ€λ₯Έ docker-compose νμΌμ μ¬μ©νκ² λμμ΅λλ€.
κ΅¬μ± λ³΅μ λ λͺ¨λ νκ²½μμ μ¬μ©ν μ μμ΅λλ€!
κ³Όμ μ λν΄ μμΈν μμ보기
μΆμ² : habr.com
