Docker

[์ƒํ™œ์ฝ”๋”ฉ] Docker

jjingle 2023. 9. 14. 11:32

Docker


๋„์ปค๊ฐ€ ๊ฐ€์ƒ๋จธ์‹ ์„ ๋งŒ๋“ค์–ด ๋ฆฌ๋ˆ…์Šค ํ™˜๊ฒฝ์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.

  • ํ•˜๋‚˜์˜ ์šด์˜์ฒด์ œ ์•ˆ์— ๊ฐ๊ฐ์˜ ์ปจํ…Œ์ด๋„ˆ -> ์‹œ๊ฐ„, ์ €์žฅ์žฅ์น˜ ์šฉ๋Ÿ‰ ์ ˆ์•ฝ
  • ์ปจํ…Œ์ด๋„ˆ : ๊ฒฉ๋ฆฌ๋œ ๊ฐ๊ฐ์˜ ์‹คํ–‰ ํ™˜๊ฒฝ

์ด๋ฏธ์ง€ pull


์ปจํ…Œ์ด๋„ˆ run


* httpd : ์•„ํŒŒ์น˜ ์›น ์„œ๋ฒ„ (์ด๋ฏธ์ง€ ๋ช…)

* test(์˜ˆ์ œ) : ์ปจํ…Œ์ด๋„ˆ ๋ช…

#์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
docker run --name test httpd

#์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ๋ฉˆ์ถค
docker stop test

#์ปจํ…Œ์ด๋„ˆ ์žฌ์‹œ์ž‘
docker start test

#์‹คํ–‰ ๋กœ๊ทธ ์กฐํšŒ
docker logs test

#์‹คํ–‰ ๋กœ๊ทธ ์‹ค์‹œ๊ฐ„
docker logs --f test

#์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์„ธ์Šค ์กฐํšŒ
docker ps

#์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ(์‹คํ–‰ ์ค‘ X)
docker rm test

#์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ
docker rm --force test

#์ด๋ฏธ์ง€ ์กฐํšŒ
docker images

#์ด๋ฏธ์ง€ ์‚ญ์ œ
docker rmi httpd

 

๋„คํŠธ์›Œํฌ


port forwarding
 : ํ˜ธ์ŠคํŠธ์˜ ํฌํŠธ์—์„œ ์ปจํ…Œ์ด๋„ˆ์˜ ํฌํŠธ๋กœ ์ „์†ก
docker run -p [ํ˜ธ์ŠคํŠธํฌํŠธ]:[์ปจํ…Œ์ด๋„ˆํฌํŠธ] [์ด๋ฏธ์ง€์ด๋ฆ„]
  •  -p , -publish : ์ปจํ…Œ์ด๋„ˆ์˜ ํฌํŠธ๋ฅผ ํ˜ธ์ŠคํŠธ๋กœ ๊ณต๊ฐœํ•œ๋‹ค (์—ฐ๊ฒฐ์‹œํ‚จ๋‹ค).

 

 

๋ช…๋ น์–ด ์‹คํ–‰


#์‰˜ : ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๋ช…๋ น์–ด๋ฅผ ์‰˜ํ”„๋กœ๊ทธ๋žจ์ด ๋ฐ›์•„์„œ ์šด์˜์ฒด์ œ์— ์ „๋‹ฌํ•˜๋Š” ์ฐฝ๊ตฌ ์—ญํ• 
#  -> ์ด ํ›„์— '#'์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ช…๋ น์–ด๋Š” 'test'์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋Œ€์ƒ์œผ๋กœ ๋‚ด๋ฆฌ๋Š” ๋ช…๋ น์–ด!
docker exec -it test /bin/sh (or bash)
# pwd
# exit   -> ์ด ํ›„๋ถ€ํ„ฐ๋Š” host๋ฅผ ๋Œ€์ƒ์œผ๋กœ ๋‚ด๋ฆฌ๋Š” ๋ช…๋ น์–ด!

* ํ„ฐ๋ฏธ๋„๊ณผ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ง€์†์ ์œผ๋กœ ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ์˜ต์…˜ : -it

  • --interactive, -i : Keep STDIN open even if not attached
  • --tty, -t : Allocate a pseudo-TTY