๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ฒœ์ฒœํžˆ, ๊พธ์ค€ํžˆ../LINUX

[Docker] ๋””์Šคํฌ ๊ณต๊ฐ„ ๋ถ€์กฑ : overlay2 ํŒŒ์ผ ์ •๋ฆฌ

by MIMI.L 2023. 12. 28.
๋ฐ˜์‘ํ˜•

์ตœ๊ทผ WRF์šฉ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋งŒ๋“ค๋ฉด์„œ ๋นŒ๋“œํ–ˆ๋‹ค ์‚ญ์ œํ–ˆ๋‹ค๋ฅผ ๋ฐ˜๋ณต์ค‘์ธ๋ฐ,

df -h๋กœ ์šฉ๋Ÿ‰์„ ํ™•์ธํ•ด๋ณด๋ฉด ๊ณ„์† ๋‚จ์€ ์šฉ๋Ÿ‰์ด ์ค„์–ด๋“ค๊ณ  ์žˆ์–ด์„œ 

์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ–ˆ๋Š”๋ฐ๋„ ๊ณ„์† ์šฉ๋Ÿ‰์ด ์ค„์–ด๋“ค๊ณ  ์žˆ์—ˆ์Œ..

 

์•„๋ž˜๋Š” ํ˜„์žฌ ๋‚ด ์‚ฌ์šฉ์ค‘์ธ ๋””์Šคํฌ ํ˜„ํ™ฉ๊ณผ docker/overlay2 ์—์„œ ์‚ฌ์šฉ์ค‘์ธ ์šฉ๋Ÿ‰์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด 1.4T ์ค‘์— 927GB๋ฅผ ์‚ฌ์šฉ์ค‘์ธ๋ฐ, ๊ทธ ์ค‘ 822GB๋ฅผ docker/overlay2 ์—์„œ ์‚ฌ์šฉ์ค‘์ด๋‹ค... 

mimi@mimi:~/wk$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           6.3G  2.7M  6.3G   1% /run
/dev/nvme0n1p5  1.4T  927G  375G  72% /
tmpfs            32G  102M   32G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/nvme0n1p1   96M   33M   64M  34% /boot/efi
tmpfs           6.3G  148K  6.3G   1% /run/user/1000
mimi@mimi:~/wk$


# ------------------------------- #

root@mimi:/var/lib/docker# sudo du -h --max-depth=1 | grep G
822G	./overlay2
822G	.
root@mimi:/var/lib/docker#

 

๋‚˜๋Š” docker rmi ์ด๋ฏธ์ง€ ๋ช…๋ น์œผ๋กœ ์‚ญ์ œ๋ฅผ ์ง„ํ–‰ํ–ˆ์—ˆ๋‹ค.

์ด๊ฑด overlay2์— ๊ณ„์† ์Œ“์—ฌ์žˆ๋Š”๊ฒƒ์ธ๊ฑธ๊นŒ..?

 

docker * prune ๋ช…๋ น์„ ์‚ฌ์šฉํ•ด์„œ ์ง€์›Œ๋ดค๋”๋‹ˆ.. ์ž๊ทธ๋งˆ์น˜ 874.6GB๊ฐ€ ์‚ด์•„๋‚ฌ๋‹ค (๋‹ค์‹œ ์“ธ ์ˆ˜ ์žˆ๋Š” ์šฉ๋Ÿ‰์œผ๋กœ ๋Œ์•„์™”๋‹น)

docker/overlay2 ๋Š” 2.5GB๋กœ ์ค„์–ด๋“ค์—ˆ๊ณ , 1.2T ์‚ฌ์šฉ๊ฐ€๋Šฅ์œผ๋กœ ๋‚˜ํƒ€๋‚œ๋‹ค !!

mimi@mimi:~/wk$ docker system prune -a 
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated to them
  - all build cache

Are you sure you want to continue? [y/N] y
Deleted Images:
# ...
29ovcc14zxwbaoc1s1xasq936
mt525by9jfei1dr365lfzed1p

Total reclaimed space: 874.6GB

# -------------------------------------------------- #

root@mimi:/var/lib/docker# sudo du -h --max-depth=1 | grep G
2.5G	./overlay2
2.6G	.
root@mimi:/var/lib/docker#

# -------------------------------------------------- #

mimi@mimi:~/wk$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           6.3G  2.9M  6.3G   1% /run
/dev/nvme0n1p5  1.4T  107G  1.2T   9% /
tmpfs            32G   99M   32G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/nvme0n1p1   96M   33M   64M  34% /boot/efi
tmpfs           6.3G  148K  6.3G   1% /run/user/1000
mimi@mimi:~/wk$

 

์ด๋ฒˆ ๊ณผ์ •์„ ํ†ตํ•ด ์•Œ๊ฒŒ๋œ๊ฑด..

docker rmi๋กœ๋งŒ ์ง€์šฐ๊ฒŒ ๋œ๋‹ค๋ฉด overlay2์— ์กด์žฌํ•˜๋Š” ๋ ˆ์ด์–ด๋“ค์€ ๋‚จ๊ฒจ๋‘๊ณ 

docker * prune์„ ์‚ฌ์šฉํ•ด์„œ ์ง€์›Œ์ค˜์•ผ docker/overlay2/ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์žˆ๋Š” ๋ ˆ์ด์–ด๋“ค๊นŒ์ง€ ํ•จ๊ป˜ ์ •๋ฆฌํ•ด์ฃผ๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ธ๋‹ค !

 

์ฐธ๊ณ ๋กœ ์œ„์—์„œ ์‚ฌ์šฉํ•œ docker system prune -a ๋ช…๋ น์€ ์—ฌ๋Ÿฌ prune ๋ช…๋ น์„ ํ•œ๋ฒˆ์— ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์œผ๋กœ 

docker * prune ๋ช…๋ น๋“ค์€ ์•„๋ž˜์—์„œ ์ฐธ๊ณ  ํ•  ๊ฒƒ

 

์ปจํ…Œ์ด๋„ˆ ์ •๋ฆฌ: ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ œ๊ฑฐ
docker container prune
์ด๋ฏธ์ง€ ์ •๋ฆฌ: ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
docker image prune -a
๋ณผ๋ฅจ ์ •๋ฆฌ: ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ณผ๋ฅจ์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
docker volume prune
๋„คํŠธ์›Œํฌ ์ •๋ฆฌ: ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋„คํŠธ์›Œํฌ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
docker network prune
์‹œ์Šคํ…œ ์ „์ฒด ์ •๋ฆฌ: ์œ„์˜ ๋ชจ๋“  ์ •๋ฆฌ ์ž‘์—…์„ ํ•œ ๋ฒˆ์— ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
docker system prune -a
-a ์˜ต์…˜์€ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๋ชจ๋“  ๊ฐ์ฒด๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ ์ค‘์ธ ๊ฐ์ฒด์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์œผ๋ฏ€๋กœ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€