Studying๐Ÿ’จ

[์›ํ‹ฐ๋“œ ๋ฐฑ์—”๋“œ ์ฑŒ๋ฆฐ์ง€] Docker - 1

hae02y 2023. 8. 6. 00:31
๋ฐ˜์‘ํ˜•

[ ๋„์ปค ์„ค์น˜ ]

 

Get Docker

 

docs.docker.com

2023.08.03 - [Deploy๐ŸŽ/Docker + K8s] - Docker ๋ž€?

 

Docker ๋ž€?

Docker ๋„์ปค๋Š” ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜ ๊ฐ€์ƒํ™” ๋„๊ตฌ์ด๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ปจํ…Œ์ด๋„ˆ๋ผ๋Š” ๋‹จ์œ„๋กœ ๊ฒฉ๋ฆฌํ•˜๊ณ  ์‹คํ–‰ํ•˜๊ณ  ๋ฐฐํฌํ•˜๋Š” ๊ธฐ์ˆ ์„ ๋งํ•œ๋‹ค. ๊ทธ๋Ÿผ ์—ฌ๊ธฐ์„œ ๋งํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ๋Š” ๋ฌด์—‡์ผ๊นŒ? Container ์ปจํ…Œ์ด๋„ˆ๋Š”

togll.tistory.com

 

 

๋„์ปค ์†Œ๊ฐœ

์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜์˜ ํŠน์ง•

์ปจํ…Œ์ด๋„ˆ๋Š” ๋ฆฌ๋ˆ…์Šค ์ปค๋„์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋งŒ๋“ค์–ด์ง„๋‹ค.

- chroot : ํŒŒ์ผ ์‹œ์Šคํ…œ์„ ๊ฒฉ๋ฆฌํ•œ๋‹ค.

- namespace : ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ฒฉ๋ฆฌํ•œ๋‹ค.

- cgroup : ํ•˜๋“œ์›จ์–ด ์ž์›์„ ๊ฒฉ๋ฆฌํ•œ๋‹ค.

 

ํ”„๋กœ์„ธ์Šค ๋‹จ์œ„์˜ ๊ฒฉ๋ฆฌํ™˜๊ฒฝ์„ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค.

 

Docker GUI

Docker Desktop ์—์„œ ์ œ๊ณตํ•˜๋Š” GUI

 

Docker CLI

ํ„ฐ๋ฏธ๋„ ํ™˜๊ฒฝ์ด๋‚˜ ์œˆ๋„์šฐ cmd๋กœ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

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

cli.md
0.00MB

 

๋„์ปคํŒŒ์ผ ์ž‘์„ฑ

FROM ์ด๋ฏธ์ง€์˜ ๋ฒ ์ด์Šค๋กœ ์‚ฌ์šฉํ•  ๋„์ปค ์ด๋ฏธ์ง€
RUN ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œํ• ๋•Œ, ํŠน์ • ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜, ๋นŒ๋“œ, ์„ค์ •๋“ฑ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค.
COPY ํ˜ธ์ŠคํŠธ ๋จธ์‹ ์˜ ํŒŒ์ผ์ด๋‚˜ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋„์ปค์ด๋ฏธ์ง€๋กœ ๋ณต์‚ฌ
WORKDIR ์ปจํ…Œ์ด๋„ˆ ๋‚ด์—์„œ ์ž‘์—… ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์„ค์ •
EXPOSE ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๊ฐ€ Listeningํ•  ํฌํŠธ๋ฅผ ์ง€์ •
ENTRYPOINT ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‹œ์ž‘๋œ๋•Œ ์‹คํ–‰ํ•  ๋ช…๋ น์–ด๋ฅผ ์ง€์ •
VOLUME ํ˜ธ์ŠคํŠธ ๋จธ์‹ ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ปจํ…Œ์ด๋„ˆ์— ๋งˆ์šดํŠธํ• ์ˆ˜์žˆ๋„๋ก ์„ค์ •

 

 

์‹ค์Šต

1. ์ด๋ฏธ์ง€ ๋‹ค์šด๋ฐ›๊ธฐ

docker pull [image์ด๋ฆ„]:[tag]

docker pull httpd

httpd ์ด๋ฏธ์ง€๋ฅผ ๋ฐ›์•„์˜จ๋‹ค.

 

2. ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰

docker run -p 8888:80 httpd

๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰์‹œํ‚จ๋‹ค. ๋กœ์ปฌ์˜ 8888 port๋กœ container 80 port์™€ ํผ๋ธ”๋ฆฌ์‹ฑ์œผ๋กœ httpd์ด๋ฏธ์ง€๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

 

3. ๋„์ปค ์ด๋ฏธ์ง€ ๋ณด๊ธฐ

docker images

 

4. ๋„์ปค ์ด๋ฏธ์ง€ ์‚ญ์ œ

docker rmi image

 

5. ๋„์ปค ํŒŒ์ผ ๋นŒ๋“œ (๋„์ปคํŒŒ์ผ -> ์ด๋ฏธ์ง€ ๋ณ€ํ™˜)

docker build . -> ํ˜„์žฌ ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ dockerfile

docker build [ํŒŒ์ผ๋ช…]

ํŒŒ์ผ๋ช…์ด DOCKERFILE์ธ ๊ฒฝ์šฐ์—๋Š” ์ƒ๋žต ๊ฐ€๋Šฅ.

 

6. ๋„์ปค ํŒŒ์ผ ๋นŒ๋“œ2

docker build -t httpd:last

Dockerfile์„ ์ด๋ฏธ์ง€ํ™” ์‹œํ‚ฌ๋•Œ, httpd์˜ ์ด๋ฏธ์ง€๋ช…๊ณผ, last๋ผ๋Š” tag๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋งŒ๋“ ๋‹ค.

 

6. attribute 

-i : ๋Œ€ํ™”ํ˜•

-t : ํ„ฐ๋ฏธ๋„

-d : detach(๋ฐฑ๊ทธ๋ผ์šด๋“œ ์‹คํ–‰)

๋ฐ˜์‘ํ˜•