docker image to tar

gosuยท2024๋…„ 3์›” 29์ผ
2
post-thumbnail

๐Ÿš€ docker images to tar

์ธํ„ฐ๋„ท ํ™˜๊ฒฝ์ด ์ž˜ ๊ตฌ์ถ•๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์—
docker image๋ฅผ ์‹ค์ œ ํŒŒ์ผ๋กœ ๋งŒ๋“ค ์ผ์€ ์ž˜ ์—†๋‹ค.
๊ทธ์ € ์ž˜ ๋นŒ๋“œํ•ด์„œ ์ด๋ฏธ์ง€๋กœ ๋งŒ๋“ค๊ณ , dockerhub์— ์—…๋กœ๋“œ ํ•˜๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ์ธํ„ฐ๋„ท์ด ์—†๋Š” ํ™˜๊ฒฝ์ด๋ผ๋ฉด?
docker image๋ฅผ ์‹ค์ œ ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด ์šด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž.

1. docker image โžก๏ธ tar ๐Ÿšฌ

  • ๋‹ค์Œ๊ณผ ๊ฐ™์ด docker build๋‚˜ docker compose up์œผ๋กœ ์ด๋ฏธ์ง€๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ณด์ž.
โ˜  ~  docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
test-api     latest    969809c19fe0   15 hours ago    470MB
mysql        8.0       c3ef21d6632d   2 days ago      603MB
nginx        latest    92b11f67642b   6 weeks ago     187MB
redis        7.0       ffc7b7efc8c1   2 months ago    130MB
mongo        4.2       9b5c4a4fdcb5   10 months ago   388MB
  • ์ด ์ด๋ฏธ์ง€๋ฅผ ์‹ค์ œ ์กด์žฌํ•˜๋Š” ํŒŒ์ผ๋กœ ๋ฐฑ์—…ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด?
  • docker save ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜๋„๋ก ํ•˜์ž.
โ˜  backup  sudo docker save -o $(pwd)/test-api.tar test-api:latest
โ˜  backup  sudo docker save -o $(pwd)/mongo.tar mongo:4.2
โ˜  backup  sudo docker save -o $(pwd)/redis.tar redis:7.0
โ˜  backup  sudo docker save -o $(pwd)/mysql.tar mysql:8.0
โ˜  backup  ls
test-api.tar  mongo.tar  mysql.tar  redis.tar                                      
  • ๋กœ์ปฌ์— ์กด์žฌํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ์ „๋ถ€ ์‚ญ์ œํ•˜๊ณ  tar์˜ ๋‚ด์šฉ๋ฌผ์„ ํ™•์ธํ•ด๋ณด์ž.
โ˜  backup  sudo docker system prune -a --volumes
โ˜  backup  sudo docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

2. tar โžก๏ธ docker image ๐Ÿ’ฝ

  • docker load ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‹ค์‹œ ์ด๋ฏธ์ง€๋กœ ๋ณต์›ํ•  ์ˆ˜ ์žˆ๋‹ค.
โ˜  backup  sudo docker load -i test-api.tar && sudo docker load -i mongo.tar && sudo docker load -i mysql.tar && sudo docker load -i redis.tar
548a79621a42: Loading layer [==================================================>]  65.53MB/65.53MB
009afd448c57: Loading layer [==================================================>]    405kB/405kB
	:
    :
    :
cc67fe8ba93c: Loading layer [==================================================>]  4.096kB/4.096kB
Loaded image ID: sha256:ffc7b7efc8c16eeff6b2e6c99127b76035473c40d550d5b501557fe87db37b42
โ˜  backup  sudo docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
test-api     latest    f0872a588a9f   5 minutes ago   470MB
mysql        8.0       c3ef21d6632d   2 days ago      603MB
redis        7.0       ffc7b7efc8c1   2 months ago    130MB
mongo        4.2       9b5c4a4fdcb5   10 months ago   388MB
โ˜  backup
profile
๊ฐœ๋ฐœ์ž ๋ธ”๋กœ๊ทธ ^0^

0๊ฐœ์˜ ๋Œ“๊ธ€