03.2.Dockers - yojulab/learn_DevOps GitHub Wiki

๋„์ž… ์ด์œ  : https://gayuna.github.io/docker/docker/

  • ํ™˜๊ฒฝ ์ผ๊ด€์„ฑ: ๊ฐœ๋ฐœ, ํ…Œ์ŠคํŠธ, ์šด์˜ ํ™˜๊ฒฝ์ด ๋™์ผํ•˜๊ฒŒ ์œ ์ง€๋จ.
  • ๋ฐฐํฌ ์ž๋™ํ™”: ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด ๋น ๋ฅด๊ณ  ์ผ๊ด€๋œ ๋ฐฐํฌ๊ฐ€ ๊ฐ€๋Šฅํ•จ.
  • ํ™•์žฅ์„ฑ: ์ˆ˜ํ‰์  ํ™•์žฅ์ด ์‰ฌ์›Œ ๋†’์€ ๊ฐ€์šฉ์„ฑ์„ ์ œ๊ณตํ•จ.
  • ํšจ์œจ์  ๋ฆฌ์†Œ์Šค ์‚ฌ์šฉ: ๊ฐ€์ƒ ๋จธ์‹ ๋ณด๋‹ค ์ ์€ ์ž์›์œผ๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ ๊ฐ€๋Šฅ.
  • CI/CD ํ†ตํ•ฉ: DevOps ํŒŒ์ดํ”„๋ผ์ธ์—์„œ ๋นŒ๋“œ, ํ…Œ์ŠคํŠธ, ๋ฐฐํฌ๊ฐ€ ์ž๋™ํ™”๋จ.

Docker ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๊ธฐ๋ณธ์ ์ธ ๋ช…๋ น์–ด

0. ์ด๋ฏธ์ง€ Pull

docker image pull openjdk:17-jdk-bullseye

1. ์ปจํ…Œ์ด๋„ˆ ์„ค์น˜ (์‹คํ–‰)

docker run -d --name my_container_name -p 8080:80 nginx
  • docker run: ์ƒˆ๋กœ์šด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ช…๋ น์–ด.
  • -d: ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์‹คํ–‰ (detached mode).
  • --name my_container_name: ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ์ง€์ •.
  • -p 8080:80: ํ˜ธ์ŠคํŠธ์˜ ํฌํŠธ 8080์„ ์ปจํ…Œ์ด๋„ˆ์˜ ํฌํŠธ 80์— ์—ฐ๊ฒฐ.
  • nginx: nginx ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰.

2. ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก ํ™•์ธ

docker ps
  • ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก์„ ํ™•์ธ.
docker ps -a
  • ์ค‘์ง€๋œ ์ปจํ…Œ์ด๋„ˆ๊นŒ์ง€ ํฌํ•จํ•œ ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก์„ ํ™•์ธ.

3. ์ปจํ…Œ์ด๋„ˆ ์ ‘์†

docker exec -it my_container_name /bin/bash
  • docker exec: ์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ์— ๋ช…๋ น์„ ๋‚ด๋ฆฌ๊ฑฐ๋‚˜ ์ ‘์†ํ•˜๋Š” ๋ช…๋ น์–ด.
  • -it: ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ๋ชจ๋“œ๋กœ ํ„ฐ๋ฏธ๋„์„ ์—ฝ๋‹ˆ๋‹ค.
  • my_container_name: ์ ‘์†ํ•  ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„.
  • /bin/bash: Bash ์‰˜์„ ์‹คํ–‰ํ•˜์—ฌ ํ„ฐ๋ฏธ๋„๋กœ ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

4. ์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€

docker stop my_container_name
  • docker stop: ์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ค‘์ง€ํ•˜๋Š” ๋ช…๋ น์–ด.

5. ์ปจํ…Œ์ด๋„ˆ ์ œ๊ฑฐ

docker rm my_container_name
  • docker rm: ์ค‘์ง€๋œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ญ์ œํ•˜๋Š” ๋ช…๋ น์–ด.

์ค‘์ง€๋˜์ง€ ์•Š์€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด ๊ฐ•์ œ๋กœ ์‚ญ์ œ:

docker rm -f my_container_name

6. ์ด๋ฏธ์ง€ ์ œ๊ฑฐ

์ปจํ…Œ์ด๋„ˆ์— ์‚ฌ์šฉ๋œ ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด, ๋จผ์ € ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ญ์ œํ•œ ํ›„ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉ.

docker rmi nginx
  • docker rmi: ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•˜๋Š” ๋ช…๋ น์–ด.