์•ˆ๋…•ํ•˜์„ธ์š”? ์ด์ „ ํฌ์ŠคํŒ…์—์„œ ์ปจํ…Œ์ด๋„ˆ์™€ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ ๊ฐœ๋…์— ๋Œ€ํ•ด ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค๋ช…ํ•ด ๋“œ๋ ธ์—ˆ๋Š”๋ฐ์š”, ์˜ค๋Š˜์€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‰ฝ๊ฒŒ ์‹ค์Šตํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ด ๋“œ๋ฆฌ๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค. ์‹œ์ž‘ํ•˜๊ธฐ ์ด์ „์—, ์ปจํ…Œ์ด๋„ˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ๋™ํ•˜๋Š” ํ™˜๊ฒฝ์„ ๋‹ด์€ ๊ฒฉ๋ฆฌ ๊ณต๊ฐ„์ด๋ผ๋Š” ๊ฒƒ์„ ๊ผญ ๊ธฐ์–ตํ•ด์ฃผ์„ธ์š”!

์˜ค๋Š˜์˜ ์‹ค์Šต์€ Flow 1๊ณผ Flow 2๋กœ ๊ตฌ๋ถ„๋ฉ๋‹ˆ๋‹ค.
– ์ฒซ ๋ฒˆ์งธ ์‹ค์Šต(Flow 1)์—์„œ๋Š” ์ด๋ฏธ ๋งŒ๋“ค์–ด์ง„ Docker Image๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
– ๋‘ ๋ฒˆ์งธ ์‹ค์Šต(Flow 2)์—์„œ๋Š” Dockerfile์„ ์ง์ ‘ ์ž‘์„ฑํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋งŒ๋“ค๊ณ  docker hub์— ๋ฐฐํฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

Flow 1

1. Docker Hub์˜ Repository์—์„œ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
2. ํ•ด๋‹น ์ด๋ฏธ์ง€๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑ ๋ฐ ๊ตฌ๋™ํ•ฉ๋‹ˆ๋‹ค.
3. ๋ธŒ๋ผ์šฐ์ €๋กœ ์ปจํ…Œ์ด๋„ˆ์˜ ์›น ์„œ๋น„์Šค๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

Containerization ์‹ค์Šต

๋งŒ์•ฝ ๋„์ปค๊ฐ€ ์—†์œผ์‹œ๋‹ค๋ฉด ์•„๋ž˜ ๋งํฌ์—์„œ ์„ค์น˜ํ•ด์ฃผ์„ธ์š”!
https://www.slideshare.net/pyrasis/docker-fordummies-44424016 (85p๋ถ€ํ„ฐ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.)

1. ์ œ๊ฐ€ ๋งŒ๋“  ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ๊ทธ ํ™˜๊ฒฝ์ด ๋‹ด๊ฒจ์žˆ๋Š” Docker Image๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ฒ ์Šต๋‹ˆ๋‹ค.

docker pull dodghek/kubernetes

2. ๋ถˆ๋Ÿฌ์˜จ Image๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

docker run -p 8855:80 --name youngho dodghek/kubernetes

  2-1. ์ปจํ…Œ์ด๋„ˆ์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ด๋ณผ๊นŒ์š”?

docker ps -l

  * ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๊ตฌ๋™๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค (Up 15 seconds)
  * 8855๋ฒˆ ํฌํŠธ๋ฅผ ๊ธฐ์–ตํ•ด๋‘์„ธ์š”! ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ ‘์†ํ•  ๋•Œ ์‚ฌ์šฉํ•  ๊ฒƒ ์ž…๋‹ˆ๋‹ค.


3. ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
๋ธŒ๋ผ์šฐ์ € ์ฐฝ์—์„œ IP:8855๋กœ ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

* Developer Works Korea ํ™ˆํŽ˜์ด์ง€๋ฅผ ๋ชจ๋ฐฉํ•œ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



Flow 2

1. ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ Dockerfile์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
2. ์ด๋ฏธ์ง€๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑ ๋ฐ ๊ตฌ๋™์‹œํ‚ต๋‹ˆ๋‹ค.
3. ๋ธŒ๋ผ์šฐ์ €๋กœ ์ปจํ…Œ์ด๋„ˆ์˜ ์›น ์„œ๋น„์Šค๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
4. ๊ณต๊ฐœ ์ €์žฅ์†Œ์ธ Docker hub์— ์ด๋ฏธ์ง€๋ฅผ ์˜ฌ๋ฆฝ๋‹ˆ๋‹ค.

Dockerization ์‹ค์Šต

1. ๋„์ปคํŒŒ์ผ์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

vi Dockerfile

  

  1.1 ๋„์ปคํŒŒ์ผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

docker build -f Dockerfile -t myimage .

  * ํƒœ๊ทธ์˜ต์…˜ -t ๋‹ค์Œ์— ๋งˆ์นจํ‘œ(.)๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

2. ์ด๋ฏธ์ง€๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

docker run -p 8866:80 --name youngho2 myimage

3. 8866๋ฒˆ ํฌํŠธ๋กœ ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

IP:8866์œผ๋กœ ๋ธŒ๋ผ์šฐ์ €์— ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค. ์ •์ƒ์ ์œผ๋กœ Web Application์ด ์ž‘๋™ํ•œ๋‹ค๋ฉด,

4. ๊ณต๊ฐœ ์ €์žฅ์†Œ์ธ Docker Hub์— ์ด๋ฏธ์ง€๋ฅผ ์˜ฌ๋ ค๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

  4-1 ๋จผ์ € ๋„์ปค ๊ณ„์ • ์ƒ์„ฑ์„ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”.

https://hub.docker.com/

  4-2 ๋„์ปค Hub์— ๋กœ๊ทธ์ธํ•ฉ๋‹ˆ๋‹ค (์œ„์—์„œ ์ƒ์„ฑํ•œ ID, PW ์ž…๋ ฅ).
  

  4-3 ์ด๋ฏธ์ง€์˜ ๋ฒ„์ „์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ํƒœ๊ทธ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

docker tag myimage dodghek/myimage:0.1

  * ๋น—๊ธˆ(/)์•ž์—๋Š” ์‚ฌ์šฉ์ž์˜ ๊ณ„์ •์„ ์ ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  4-4 ๋„์ปค Hub์— ํƒœ๊ทธ๊ฐ€ ์ ์šฉ๋œ ์ด๋ฏธ์ง€๋ฅผ ์˜ฌ๋ ค๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

docker push dodghek/myimage:0.1

  

5. Hub์˜ Repositories์— ์ƒˆ๋กœ์šด ์ €์žฅ์†Œ๊ฐ€ ์ƒ๊ธด ๊ฒƒ์„ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


TIP

๋„์ปค ์ปจํ…Œ์ด๋„ˆ์— ์ง์ ‘ ์ ‘์†ํ•˜๊ธฐ

docker exec -it ์ปจํ…Œ์ด๋„ˆ์ด๋ฆ„ /bin/bash

์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†ํ•œ ํ›„, ํŒจํ‚ค์ง€ ์„ค์น˜ํ•˜์ง€

apt-get update
apt-get install ํŒจํ‚ค์ง€๋ช…

์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œํ•˜๊ธฐ

docker rm ์ปจํ…Œ์ด๋„ˆ์˜ ์ด๋ฆ„

์ด๋ฏธ์ง€ ์‚ญ์ œํ•˜๊ธฐ

docker rmi ์ด๋ฏธ์ง€

๋„์ปค ํ—ˆ๋ธŒ์—์„œ ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰ํ•˜๊ธฐ

docker search ๊ฒ€์ƒ‰์–ด

์ด๋ฏธ์ง€๋ฅผ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

docker pull ์ด๋ฏธ์ง€์ด๋ฆ„

์ฐธ๊ณ ๋ฌธํ—Œ

๋„์ปค ๊ณต์‹ ํŽ˜์ด์ง€ : https://docs.docker.com/