A A
[Docker] ์ด๋ฏธ์ง€ ๊ด€๋ฆฌํ•˜๊ธฐ: Docker ์ด๋ฏธ์ง€ ํšจ์œจ์ ์œผ๋กœ ๋‹ค๋ฃจ๊ธฐ

Docker ์ด๋ฏธ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. Docker ์ด๋ฏธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๋ชจ๋“  ํŒŒ์ผ๊ณผ ์„ค์ •์„ ํฌํ•จํ•˜๊ณ  ์žˆ์–ด, ํšจ์œจ์ ์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ์™€ ๊ด€๋ฆฌ์— ํ•ต์‹ฌ์ ์ธ ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.

 

์ด ํฌ์ŠคํŠธ์—์„œ๋Š” Docker Hub์—์„œ ์ด๋ฏธ์ง€๋ฅผ ํ™•์ธํ•˜๊ณ , ๋‹ค์šด๋กœ๋“œ(pull)ํ•˜๋ฉฐ, ์‚ญ์ œํ•˜๋Š” ๋ฐฉ๋ฒ•๊นŒ์ง€ ๋‹จ๊ณ„๋ณ„๋กœ ์„ค๋ช…๋“œ๋ฆด๊ฒŒ์š”. ํŠนํžˆ MySQL ์ด๋ฏธ์ง€๋ฅผ ์˜ˆ์‹œ๋กœ ๋“ค์–ด ์‹ค์Šต๋„ ํ•จ๊ป˜ ์ง„ํ–‰ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค


Docker Hub์—์„œ ์ด๋ฏธ์ง€ ์ •๋ณด ํ™•์ธํ•˜๊ธฐ

Docker Hub๋Š” Docker ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•˜๊ณ  ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณต์‹ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์ž…๋‹ˆ๋‹ค.

๋‹ค์–‘ํ•œ ์˜คํ”ˆ ์†Œ์Šค ์ด๋ฏธ์ง€๋ฅผ ์‰ฝ๊ฒŒ ๊ฒ€์ƒ‰ํ•˜๊ณ  ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์–ด, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ๊ณผ ๋ฐฐํฌ์— ํฐ ๋„์›€์„ ์ค๋‹ˆ๋‹ค.

Docker Hub ๋ฐฉ๋ฌธํ•˜๊ธฐ

Docker Hub์— ์ ‘์†ํ•˜์—ฌ ์›ํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ๊ฒ€์ƒ‰ํ•ด๋ณด์„ธ์š”.

https://hub.docker.com/

 

 

 

Docker Hub Container Image Library | App Containerization

Increase your reach and adoption on Docker Hub With a Docker Verified Publisher subscription, you'll increase trust, boost discoverability, get exclusive data insights, and much more.

hub.docker.com

 

์—ฌ๊ธฐ์„œ ์˜ˆ๋ฅผ ๋“ค์–ด, node๋‚˜ mysql๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์ด๋ฏธ์ง€๋ฅผ ์ฐพ์•„๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ(pull)ํ•˜๊ธฐ

Docker ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋จผ์ € ๋กœ์ปฌ ์‹œ์Šคํ…œ์œผ๋กœ ๋‹ค์šด๋กœ๋“œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ pull์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ

๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์€ ์ด๋ฏธ์ง€์˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ์ด๋ฆ„๊ณผ ํƒœ๊ทธ๋ฅผ ์ง€์ •ํ•˜์—ฌ ๋‹ค์šด๋กœ๋“œํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

ํƒœ๊ทธ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ latest ํƒœ๊ทธ๊ฐ€ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

docker image pull node:20.15.1

์œ„ ๋ช…๋ น์–ด๋Š” node ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ 20.15.1 ํƒœ๊ทธ๊ฐ€ ๋ถ™์€ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’ก ์ฐธ๊ณ : ํƒœ๊ทธ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด latest ํƒœ๊ทธ๊ฐ€ ์ž๋™์œผ๋กœ ์ง€์ •๋ฉ๋‹ˆ๋‹ค.

 

๋‹ค์ด์ œ์ŠคํŠธ(Digest)๋ฅผ ์‚ฌ์šฉํ•œ ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ

์ด๋ฏธ์ง€๋ฅผ ํŠน์ •ํ•œ ์ƒํƒœ๋กœ ์ •ํ™•ํžˆ ๋‹ค์šด๋กœ๋“œํ•˜๋ ค๋ฉด ๋‹ค์ด์ œ์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์ด์ œ์ŠคํŠธ๋Š” ์ด๋ฏธ์ง€์˜ ๊ณ ์œ ํ•œ ํ•ด์‹œ๊ฐ’์œผ๋กœ, ์ด๋ฏธ์ง€์˜ ๋ณ€๊ฒฝ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

docker image pull node@sha256:b21bcf3e7b6e68d723eabedc6067974950941167b5d7a9e414bd5ac2011cd1c4

์œ„ ๋ช…๋ น์–ด๋Š” node ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ ํŠน์ • ๋‹ค์ด์ œ์ŠคํŠธ๋ฅผ ๊ฐ€์ง„ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.


๋‹ค์šด๋กœ๋“œํ•œ ์ด๋ฏธ์ง€ ํ™•์ธํ•˜๊ธฐ

๋‹ค์šด๋กœ๋“œํ•œ ์ด๋ฏธ์ง€๋Š” docker image ls ๋ช…๋ น์–ด๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

docker image ls

์˜ˆ์‹œ ์ถœ๋ ฅ:

REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
node         20.15.1   4efd4a4c24f5   6 months ago   1.09GB

์—ฌ๊ธฐ์„œ REPOSITORY๋Š” ์ด๋ฏธ์ง€์˜ ์ด๋ฆ„, TAG๋Š” ๋ฒ„์ „ ๋˜๋Š” ๋ณ„์นญ, IMAGE ID๋Š” ๊ณ ์œ  ์‹๋ณ„์ž, CREATED๋Š” ์ƒ์„ฑ ์‹œ๊ฐ„, SIZE๋Š” ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.


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

๋” ์ด์ƒ ํ•„์š”ํ•˜์ง€ ์•Š์€ ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•˜์—ฌ ๋””์Šคํฌ ๊ณต๊ฐ„์„ ํ™•๋ณดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Docker๋Š” ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.

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

ํŠน์ • ํƒœ๊ทธ๊ฐ€ ์žˆ๋Š” ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด docker image rm ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

docker image rm node:20.15.1

์˜ˆ์‹œ ์ถœ๋ ฅ:

Untagged: node:20.15.1
Untagged: node@sha256:6326b52a508f0d99ffdbfaa29a69380321b215153db6f32974835bac71b38fa4
Deleted: sha256:4efd4a4c24f50c8425922423a2c347aea8e44a59000a201989e9c3c45b6e60eb
...

์ด ๋ช…๋ น์–ด๋Š” ์ง€์ •ํ•œ ์ด๋ฏธ์ง€ ํƒœ๊ทธ๋ฅผ ์–ธํƒœ๊ทธ(Untagged)ํ•˜๊ณ , ํ•ด๋‹น ์ด๋ฏธ์ง€๊ฐ€ ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์‚ญ์ œ(Delete)ํ•ฉ๋‹ˆ๋‹ค.


๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€(Dangling Image) ์‚ญ์ œํ•˜๊ธฐ

๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€๋Š” ํƒœ๊ทธ๊ฐ€ ์—†๋Š” ์ด๋ฏธ์ง€๋กœ, ๋” ์ด์ƒ ์ฐธ์กฐ๋˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค.

์ด๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด docker image prune ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

docker image prune

์œ„ ๋ช…๋ น์–ด๋Š” ํƒœ๊ทธ๊ฐ€ ์—†๋Š” ๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€๋งŒ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.


์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๋ชจ๋“  ์ด๋ฏธ์ง€ ์‚ญ์ œํ•˜๊ธฐ

๋ชจ๋“  ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด -a ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ ํ”„๋กฌํ”„ํŠธ ํ™•์ธ ์—†์ด ์‚ญ์ œ๋˜๋ฏ€๋กœ ์ฃผ์˜๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

docker image prune -a

์‹คํ–‰ ์‹œ ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค:

WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N]

ํ™•์ธ ํ›„ y๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋ชจ๋“  ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€๊ฐ€ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.

docker image prune -f -a

์œ„ ๋ช…๋ น์–ด๋Š” -f ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•˜์—ฌ ํ”„๋กฌํ”„ํŠธ ํ™•์ธ ์—†์ด ๊ฐ•์ œ๋กœ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.


MySQL ์ด๋ฏธ์ง€ ๊ด€๋ฆฌ ์‹ค์Šต

์ด์ œ ์‹ค์ œ๋กœ MySQL ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ๊ด€๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ Docker ์ด๋ฏธ์ง€๋ฅผ ํ†ตํ•ด ์†์‰ฝ๊ฒŒ ์„ค์น˜ํ•˜๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

๋จผ์ €, Docker Hub์—์„œ MySQL ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

MySQL 8.3.0 ๋ฒ„์ „ ๋‹ค์šด๋กœ๋“œ

docker image pull mysql:8.3.0

์˜ˆ์‹œ ์ถœ๋ ฅ:

8.3.0: Pulling from library/mysql
c6a0976a2dbe: Pull complete
8dd4f8e415ca: Pull complete
...
Digest: sha256:9de9d54fecee6253130e65154b930978b1fcc336bcc86dfd06e89b72a2588ebe
Status: Downloaded newer image for mysql:8.3.0
docker.io/library/mysql:8.3.0

MySQL ์ตœ์‹  ๋ฒ„์ „(latest) ๋‹ค์šด๋กœ๋“œ

docker image pull mysql

๐Ÿ’ก ์ฐธ๊ณ : ํƒœ๊ทธ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด latest ํƒœ๊ทธ๊ฐ€ ์ž๋™์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

์˜ˆ์‹œ ์ถœ๋ ฅ:

Using default tag: latest
latest: Pulling from library/mysql
f7fa64c7935f: Pull complete
bbcaadfa8390: Pull complete
...
Digest: sha256:0255b469f0135a0236d672d60e3154ae2f4538b146744966d96440318cc822c6
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest

๋‹ค์šด๋กœ๋“œํ•œ ์ด๋ฏธ์ง€ ๋ชฉ๋ก ํ™•์ธ

๋‹ค์šด๋กœ๋“œํ•œ ์ด๋ฏธ์ง€๋ฅผ ํ™•์ธํ•˜๋ ค๋ฉด ๋‹ค์‹œ ํ•œ ๋ฒˆ docker image ls ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

docker image ls

 

์˜ˆ์‹œ ์ถœ๋ ฅ:

REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
mysql        latest    50296fefa2a2   2 months ago   625MB

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

๋‹ค์šด๋กœ๋“œํ•œ MySQL ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

docker image rm mysql

์˜ˆ์‹œ ์ถœ๋ ฅ:

Untagged: mysql:latest
Untagged: mysql@sha256:0255b469f0135a0236d672d60e3154ae2f4538b146744966d96440318cc822c6
Deleted: sha256:50296fefa2a2dbc64120735564ad18b0e51681c58db3b4e5ca17aefad8259c5a
...

์ด ๋ช…๋ น์–ด๋Š” mysql:latest ์ด๋ฏธ์ง€๋ฅผ ์–ธํƒœ๊ทธํ•˜๊ณ , ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€ ๋ ˆ์ด์–ด๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.


์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ชจ๋“  ์ด๋ฏธ์ง€๋ฅผ ํ”„๋กฌํ”„ํŠธ ํ™•์ธ ์—†์ด ์‚ญ์ œํ•˜๊ธฐ

๋งŒ์•ฝ ์‹œ์Šคํ…œ์— ๋” ์ด์ƒ ํ•„์š” ์—†๋Š” ๋ชจ๋“  ์ด๋ฏธ์ง€๋ฅผ ํ•œ ๋ฒˆ์— ์‚ญ์ œํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
docker image prune -f -a

์ด ๋ช…๋ น์–ด๋Š” ํ”„๋กฌํ”„ํŠธ ํ™•์ธ ์—†์ด ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๋ชจ๋“  ์ด๋ฏธ์ง€๋ฅผ ๊ฐ•์ œ๋กœ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.

๋””์Šคํฌ ๊ณต๊ฐ„์„ ํ™•๋ณดํ•  ๋•Œ ์œ ์šฉํ•˜์ง€๋งŒ, ์‚ญ์ œ ์ „์— ๊ผญ ํ•„์š”ํ•œ ์ด๋ฏธ์ง€๊ฐ€ ์—†๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.