Ops/Docker

[Docker] 도커 save, load VS Export, Import 차이점

장그래 2022. 9. 20. 15:25
반응형

 

개요

사용 중인 컨테이너 혹은 이미지를 아카이빙 할 수 있는 Export / Save 차이점을 알아보자

Export &  Import

먼저 Export 명령어 먼저 살펴보자.
Docker --help 명령어를 통해 Export가 무엇인지 쉽게 알 수 있다. 

$ docker export --help

Usage:	docker export [OPTIONS] CONTAINER

Export a container's filesystem as a tar archive

Options:
  -o, --output string   Write to a file, instead of STDOUT

Export란 Container를 Tar 파일 시스템으로 Archive 하는 것이다. 즉 "컨테이너를 파일로 추출한다"라고 이해하면 편할 것 같다.  

Export [예제]

docker export -o appjs.tar appjs


다음은 Import에 대해 알아보자.
--help 명령어를 통해 살펴보면, Tar 파일을 바탕으로 도커 이미지를 생성하는 것을 알 수 있다.

$ docker import --help

Usage:	docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Import the contents from a tarball to create a filesystem image

Options:
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Set commit message for imported image

Import [예제]

docker import appjs.tar appjs

Save &  Load

save도 역시 help 명령어를 통해 알아보면, 이미지를 Tar 파일로 archive 한다는 내용이다.
위 Export와 차이점은 Export는 컨테이너를, Save는 이미지를 archive 하는 것이다.
(차이점으로는 save는 history를 포함하고 있지만, export는 포함하고 있지 않다)

$ docker save --help

Usage:	docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Options:
  -o, --output string   Write to a file, instead of STDOUT

Save [예제]

docker save -o myappjs.tar appjs:v1

Load도  help 명령어를 통해 알아보면, Tar 파일로부터 이미지를 불러온다는 내용이다.

$ docker load --help

Usage:	docker load [OPTIONS]

Load an image from a tar archive or STDIN

Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

Load [예제]

docker load -i app.tar

차이점

Export와 Save는 컨테이너를 저장하고, 이미지를 저장하는 차이점이 있다.

그럼 같은 Tar 파일이라면 컨테이너와 이미지를 어떻게 구분할 수 있을까?
Tar 파일에 대해 압축을 해제해보면 알 수 있다.

Save한 Tar 파일은 이미지 레이어 구조가 포함되어 있다.

$ tar -tf save.tar 
1b3d6268945283a0944fa71efffe7465644bc6513a4d12b7d38b36c7ec6ae6c3/
1b3d6268945283a0944fa71efffe7465644bc6513a4d12b7d38b36c7ec6ae6c3/VERSION
1b3d6268945283a0944fa71efffe7465644bc6513a4d12b7d38b36c7ec6ae6c3/json
1b3d6268945283a0944fa71efffe7465644bc6513a4d12b7d38b36c7ec6ae6c3/layer.tar
251a7d582ca615152781a803c12f1948c28b2a5c226c84884033ec97f5fedd7a/
251a7d582ca615152781a803c12f1948c28b2a5c226c84884033ec97f5fedd7a/VERSION
251a7d582ca615152781a803c12f1948c28b2a5c226c84884033ec97f5fedd7a/json
251a7d582ca615152781a803c12f1948c28b2a5c226c84884033ec97f5fedd7a/layer.tar
2f999d01f43ecde4bd900fcf40eb3cf8b3e072be2242bc935d5c068264071b8d/
2f999d01f43ecde4bd900fcf40eb3cf8b3e072be2242bc935d5c068264071b8d/VERSION
2f999d01f43ecde4bd900fcf40eb3cf8b3e072be2242bc935d5c068264071b8d/json
2f999d01f43ecde4bd900fcf40eb3cf8b3e072be2242bc935d5c068264071b8d/layer.tar
4306f5747062e8ec33a7c323d462cd277fab20ec54b4a46c758ebffbc8c7bea9/
4306f5747062e8ec33a7c323d462cd277fab20ec54b4a46c758ebffbc8c7bea9/VERSION
4306f5747062e8ec33a7c323d462cd277fab20ec54b4a46c758ebffbc8c7bea9/json
4306f5747062e8ec33a7c323d462cd277fab20ec54b4a46c758ebffbc8c7bea9/layer.tar

Export 한 Tar 파일은 루트 파일 시스템을 전부 담고 있음

tar -tf export.tar
var/lib/systemd/deb-systemd-helper-enabled/
var/lib/systemd/deb-systemd-helper-enabled/apt-daily-upgrade.timer.dsh-also
var/lib/systemd/deb-systemd-helper-enabled/apt-daily.timer.dsh-also
var/lib/systemd/deb-systemd-helper-enabled/cron.service.dsh-also
var/lib/systemd/deb-systemd-helper-enabled/fstrim.timer.dsh-also
var/lib/systemd/deb-systemd-helper-enabled/motd-news.timer.dsh-also
var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/
var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/cron.service
var/lib/systemd/deb-systemd-helper-enabled/timers.target.wants/
var/lib/systemd/deb-systemd-helper-enabled/timers.target.wants/apt-daily-upgrade.timer
var/lib/systemd/deb-systemd-helper-enabled/timers.target.wants/apt-daily.timer
var/lib/systemd/deb-systemd-helper-enabled/timers.target.wants/fstrim.timer
var/lib/systemd/deb-systemd-helper-enabled/timers.target.wants/motd-news.timer
var/lib/vim/
var/lib/vim/addons/
var/local/
반응형