๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ ํŒ/์„œ๋น„์Šค & ์•„ํ‚คํ…์ฒ˜

docker

by 1mj 2022. 3. 11.
Docker ๋Š” ์ปจํ…Œ์ด๋„ˆ ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•˜์—ฌ
์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ํ•„์š”ํ•œ ํ™˜๊ฒฝ์„ ๋น ๋ฅด๊ฒŒ ๊ตฌ์ถ•ํ•˜๊ณ  ํ…Œ์ŠคํŠธ ๋ฐ ๋ฐฐํฌ๋ฅผ ๋„์™€์ฃผ๋Š” ํ”Œ๋žซํผ


Container ๋ž€?

  • ๋ฆฌ์†Œ์Šค๋ฅผ ๋…ผ๋ฆฌ์ ์œผ๋กœ(๋ฌผ๋ฆฌ์ ์ด ์•„๋‹ˆ๋ผ!) ๊ตฌ๋ถ„ํ•˜์—ฌ ๋ณ„๋„์˜ ์„œ๋ฒ„์ธ ๊ฒƒ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๊ธฐ์ˆ ์ด๋‹ค.
  • ์ž‘์€ ๋‹จ์œ„, ๋…๋ฆฝ์ ์ธ ๋ฐฐํฌ์™€ ์‹คํ–‰์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ด์ฃผ๋Š” ์ผ์ข…์˜ ๊ฐ€์ƒ ๋จธ์‹ ์ด๋‹ค.
  • ์†Œํ”„ํŠธ์›จ์–ด ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ํŠน์ • ๋ฒ„์ „์˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด ๋Ÿฐํƒ€์ž„ ๋ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ฐ™์€ ์ข…์† ํ•ญ๋ชฉ๊ณผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ”๋“œ๋ฅผ ํ•จ๊ป˜ ํฌํ•จํ•˜๋Š” ๊ฒฝ๋Ÿ‰ ํŒจํ‚ค์ง€๋กœ ๋น ๋ฅธ ๋นŒ๋“œ์™€ ๋ฐฐํฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

- Traditional Deployment

 ํ•œ ๋ฌผ๋ฆฌ ์„œ๋ฒ„์—์„œ ๋‹ค์ˆ˜์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋ฆฌ์†Œ์Šค๋ฅผ ๊ณต์œ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋น„ํšจ์œจ์ ์ด๊ณ , ์„œ๋ฒ„ ์ข…๋ฃŒ ์‹œ ์‹คํ–‰ ์ค‘์ธ ๋ชจ๋“  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ข…๋ฃŒ๋œ๋‹ค.

 

- Virtualized Deployment

 ๊ฐ€์ƒํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•œ ๋ฌผ๋ฆฌ์ ์ธ ์„œ๋ฒ„ ๋‚ด์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๋งˆ๋‹ค ๊ฐ€์ƒ ๋จธ์‹ ์œผ๋กœ ์„œ๋ฒ„๋ฅผ ๋ถ„๋ฆฌํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ๋ฆฌ์†Œ์Šค๋ฅผ ํ•„์š”ํ•œ๋งŒํผ ํ• ๋‹นํ•˜์—ฌ ํšจ์œจ์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.

 

- Container Deployment

 ๊ฐ€์ƒํ™” ๋ฐฉ์‹์—์„œ๋Š” ๊ฐ€์ƒ ๋จธ์‹ ์œผ๋กœ ์„œ๋ฒ„๋ฅผ ๋ถ„๋ฆฌํ•  ๋•Œ ๊ฐ VM๋งˆ๋‹ค OS๋ฅผ ๊ฐ–๋Š”๋‹ค. ์ปจํ…Œ์ด๋„ˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐ„์— OS๋ฅผ ๊ณต์œ ํ•œ๋‹ค. VM๋ณด๋‹ค ๊ฐ€๋ณ๊ณ  ํ™•์žฅ์„ฑ์ด ์ข‹๋‹ค.


๊ฐ€์ƒ ๋จธ์‹ ๊ณผ ์ปจํ…Œ์ด๋„ˆ์˜ ์ฐจ์ด

- ๊ฐ€์ƒ ๋จธ์‹  (VM)
 ๊ฐ VM ๋งˆ๋‹ค ๋…๋ฆฝ๋œ ์‹คํ–‰ ํ™˜๊ฒฝ์„ ์ œ๊ณตํ•œ๋‹ค. ์ตœ์†Œ GB ๋‹จ์œ„์˜ ๊ณต๊ฐ„์ด ํ•„์š”ํ•˜๋ฉฐ VM ์ˆ˜์— ๋น„๋ก€ํ•ด ๋Š˜์–ด๋‚œ๋‹ค. 


- ์ปจํ…Œ์ด๋„ˆ
 ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ฒฉ๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ˆ˜์ค€์—์„œ ์ด๋ฃจ์–ด์ง€๋Š” ๊ฐ€์ƒํ™” ๋ฐฉ๋ฒ•์ด๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ํฌ๊ธฐ๊ฐ€ MB ๋‹จ์œ„์ด๊ณ  ์„œ๋ฒ„์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ๋ณ„๋„๋กœ ํ• ๋‹นํ•  ํ•„์š”๊ฐ€ ์—†์ด ํšจ์œจ์ ์ด๊ณ  ๋™์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. VM์€ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒจ๋„ ๊ฐ๊ฐ์˜ VM์ด ๋ถ„๋ฆฌ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ์—†์ง€๋งŒ ์ปจํ…Œ์ด๋„ˆ๋Š” ๋ณด์•ˆ์— ์ทจ์•ฝํ•˜๋‹ค.

→ ์ปจํ…Œ์ด๋„ˆ๋Š” ํ•œ OS๋ฅผ ๊ณต์œ ํ•˜๋Š” ๊ตฌ์กฐ์ด๊ณ , VM์€ ๊ฐ๊ฐ์˜ OS๋ฅผ ํฌํ•จํ•˜๋Š” ๊ตฌ์กฐ์ด๋‹ค.


Docker

 ๋„์ปค๋Š” Go ์–ธ์–ด๋กœ ์ž‘์„ฑ๋œ ๋ฆฌ๋ˆ…์Šค ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜ ์˜คํ”ˆ์†Œ์Šค ๊ฐ€์ƒํ™” ํ”Œ๋žซํผ์ด๋‹ค. ์ฆ‰, ์ปจํ…Œ์ด๋„ˆ ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค์–ด๋†“์€ ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค. ์‹ค์ œ๋กœ ์—ฌ๋Ÿฌ OS ๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ฏ€๋กœ ์šฉ๋Ÿ‰์ด ์ ๊ณ  ์‹คํ–‰ ์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค.

 ๋„์ปค์—์„œ ์ปจํ…Œ์ด๋„ˆ๋Š” ์†Œํ”„ํŠธ์›จ์–ด ์‹คํ–‰์— ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ์„ ํฌํ•จ(์ฝ”๋“œ, ๋Ÿฐํƒ€์ž„, ์‹œ์Šคํ…œ ๋„๊ตฌ, ์‹œ์Šคํ…œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋“ฑ)ํ•˜๋Š” ์™„์ „ํ•œ ํŒŒ์ผ ์‹œ์Šคํ…œ์ด๋‹ค.

 

๋„์ปค ์ด๋ฏธ์ง€

 ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰์— ํ•„์š”ํ•œ ํŒŒ์ผ๊ณผ ์„ค์ • ๊ฐ’ ๋“ฑ์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ธฐ๋ณธ์ด ๋œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด๋Š” ์žฌ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ์ปจํ…Œ์ด๋„ˆ๋Š” ์ด๋ฏธ์ง€๋ฅผ ์‹คํ–‰ํ•œ ์ƒํƒœ(์ด๋ฏธ์ง€๋ฅผ ์ปจํ…Œ์ด๋„ˆ์— ๋‹ด์•„ ์‹คํ–‰) ๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์œผ๋‹ˆ ๊ฐ™์€ ์ด๋ฏธ์ง€์—์„œ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๋„์ปค ๋ ˆ์ด์–ด

 ๋„์ปค ์ด๋ฏธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰์„ ์œ„ํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด ์šฉ๋Ÿ‰์ด ํฐ๋ฐ ์—ฌ๊ธฐ์„œ ํŒŒ์ผ ํ•˜๋‚˜๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ๋‹ค๊ณ  ๋‹ค์‹œ ๋‹ค์šด ๋ฐ›๋Š”๋‹ค๋ฉด ํšจ์œจ์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. ๊ทธ๋ž˜์„œ ๋ ˆ์ด์–ด๋ผ๋Š” ๊ฐœ๋…์„ ์‚ฌ์šฉํ•ด ์ฝ๊ธฐ ์ „์šฉ ๋ ˆ์ด์–ด๋กœ ๊ตฌ์„ฑ๋œ ์ด๋ฏธ์ง€์— ํŒŒ์ผ์ด ์ถ”๊ฐ€๋˜๊ฑฐ๋‚˜ ์ˆ˜์ •๋˜๋ฉด ์ƒˆ๋กœ์šด ๋ ˆ์ด์–ด๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. 

 

๋„์ปค ์‹œ์ž‘ํ•˜๊ธฐ

- ์„ค์น˜ (root ๊ถŒํ•œ)

curl -fsSL https://get.docker.com/ | sudo shโ€‹

 

- ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

 

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

docker ps [OPTIONS]

 

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

docker stop [OPTIONS] CONTAINER [CONTAINER...]

 

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

docker rm [OPTIONS] CONTAINER [CONTAINER...]

 

- ์ปจํ…Œ์ด๋„ˆ ๋กœ๊ทธ ๋ณด๊ธฐ

docker logs [OPTIONS] CONTAINER

 

- ์ด๋ฏธ์ง€ ๋ชฉ๋ก ํ™•์ธ

docker images [OPTIONS] [REPOSITORY[:TAG]]

 

- ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

 

- ์ด๋ฏธ์ง€ ์‚ญ์ œ

docker rmi [OPTIONS] IMAGE [IMAGE...]

 

์ฐธ๊ณ ์ž๋ฃŒ ๋ฐ ์ถœ์ฒ˜ ๐Ÿ™‡‍โ™‚๏ธ

https://cloud.google.com/learn/what-are-containers?hl=ko 

https://notepad96.tistory.com/entry/%EC%BB%A8%ED%85%8C%EC%9D%B4%EB%84%88Container%EB%9E%80

https://daaa0555.tistory.com/464

https://cultivo-hy.github.io/docker/image/usage/2019/03/14/Docker%EC%A0%95%EB%A6%AC/

 

'๊ฐœ๋ฐœ ํŒ > ์„œ๋น„์Šค & ์•„ํ‚คํ…์ฒ˜' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

DevOps  (0) 2022.03.23
ํ•˜๋“œ์›จ์–ด ๊ฐ€์ƒํ™” ์ข…๋ฅ˜  (0) 2022.03.22
SOA (Service Oriented Architecture)  (0) 2022.03.08
MSA (MicroService Architecture)  (0) 2022.03.08
TDD (Test-Driven-Development)  (0) 2022.03.07

๋Œ“๊ธ€