Docker λ₯Ό μ€ν μμλ λͺ¨λλ₯Ό μ€μ νλ μ΅μ μ΄ 2κ°μ§ μλ€.
- Detach Mode (Background μ€ν)
- docker command : start
- docker option : --detach / -d
- docker-compose options : -d
- Attach Mode (Foreground μ€ν)
- docker command : run
- docker option : --attach / -a
- docker-compose options : μμ
Background vs Foreground
μ°Έκ³ μλ£ : https://www.baeldung.com/linux/foreground-background-process
A process that connects to the terminal is called a foreground job. A job is said to be in the foreground because it can communicate with the user via the screen and the keyboard.
On the other hand, a process that disconnects from the terminal and cannot communicate with the user is called a background job. If the background job requires interaction with the user, it will stop and wait until establishing a connection to the terminal.
We can place the jobs that do not require interaction from the user as they run (like sorting a large file) in the background. This allows the user to access the terminal and continue to work, instead of waiting for a long job to finish:
Detach Mode (container background)
- Docker λ₯Ό Service ννλ‘ μ€νν λ μ¬μ©λλ λ°©μμΌλ‘ terminal μ μ’ λ£ν΄λ μ§μμ μΌλ‘ process μ μ€νμ΄ μ μ§λλ€.
- container λ΄μμ program μ΄ foreground λ‘ μ€ν λμ΄ μμ΄μΌ νκ³ , κ·Έλ μ§ μμΌλ©΄ container λ μλμΌλ‘ μ’
λ£λλ€.
- μλ₯Ό λ€μ΄ ubuntu image λ₯Ό
-d
μ΅μ μΌλ‘ μ€νν κ²½μ° λ°λ‘ μ’ λ£λ¨ - λ³λμ Server application λ±μ foreground λ‘ μ€νν΄μΌ ν¨
- μλ₯Ό λ€μ΄ ubuntu image λ₯Ό
How to run
- μμ±λ container λ₯Ό
docker start
command λ‘ μ€νν κ²½μ° background μμ μ€νλλ€. - container μμ± μ μ¬μ©νλ
docker run
command μ-d
μ΅μ μ λΆμμΌλ‘μ¨ background μμ μ€νλκ² ν μ μλ€.
Container log
log
μ΅μ μ μ¬μ©νμ¬ μΆλ ₯λλ log λ₯Ό νμΈ κ°λ₯νλ€$ docker log {container_id or container_name}
- νμ§λ§, κΈ°λ³Έμ μΌλ‘ Standard stream μ΄ νμ±νλμ§ μμ μνλ‘ container λ₯Ό μ€ννκΈ° λλ¬Έμ, user input μ΄ λΆκ°λ₯νλ€.
Access to container
- μ΄λ―Έ Detach Mode λ‘ μ€νλμ΄ μλ container μ κ²½μ°,
-it
μ΅μ μ ν΅ν΄ Standard stream μ νμ±ννμ¬ μ¬μ©ν μ μλ€.$ docker exec -it {container_id or container_name} /bin/bash
- νΉμ μ€ν μ,
-a
μ΅μ μ μ¬μ©νλ©΄ Foreground λ‘ μ€νλκΈ° λλ¬Έμ, terminal μ ν΅ν Standard stream μ΄ μ¬μ© κ°λ₯νλ€.
Attach Mode (container foreground)
- νμ¬ μ€ν μ€μΈ terminal μ container μ λμ μνλ₯Ό μΆλ ₯νλ λ°©μμΌλ‘, container μ λμμ 보기 μ½κΈ° λλ¬Έμ test, debug μμ μ¬μ©λλ€.
- terminal κ³Ό process κ° λΆλͺ¨ - μμμΌλ‘ μ°κ²°λκΈ° λλ¬Έμ, terminal μ μ°κ²°μ΄ μ’ λ£λλ©΄ container λ μ’ λ£λκ² λλ€.
- foreground λ‘ μ€ννλ©΄μ μ€ν μνλ₯Ό μ μ§νκ³ μΆλ€λ©΄, tmux λ±μΌλ‘ λ°λ‘ terminal process λ₯Ό κ΄λ¦¬ν νμκ° μλ€.
- docker-compose λ κΈ°λ³Έμ μΌλ‘ attach mode λ‘ μ€νλλ€.
'π§π»βπ» Develop > Docker' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Docker RUN vs ENTRYPOINT vs CMD (0) | 2023.05.09 |
---|
λκΈ