[Docker](EN) How to save or load Docker image file

Update(2020.03.28): Add basic form example

Save and Load docker image files.


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)
  • Docker


Save docker image to file

docker save

Basic Form

docker save [OPTIONS] IMAGE(by tag) [IMAGE...]

Basic Form Example

sudo docker save nginx:stable > nginx-stable-image.tar
sudo docker save nginx:stable -o nginx-stable-image.tar

Options

  • --output , -o: Specify output file name.

Examples

  • docker images list
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               stable              ac44715da54a        3 weeks ago         109MB
centos              centos7.5.1804      cf49811e3cdb        3 months ago        200MB
  • centos image example by using redirection
$ sudo docker save centos:centos7.5.1804 > centos-centos7.5.1804-image.tar
$ ls -al centos-centos7.5.1804-image.tar
-rw-rw-r-- 1 twpower twpower 207841280 Jul  4 22:55 centos-centos7.5.1804-image.tar
  • nginx image example by using -o option
$ sudo docker save nginx:stable -o nginx-stable-image.tar
$ ls -al nginx-stable-image.tar
-rw------- 1 root root 113060352 Jul  4 22:56 nginx-stable-image.tar


Load docker image from file

docker load

Basic Form

docker load [OPTIONS]

Basic Form Example

$ sudo docker load < nginx-stable-image.tar
$ sudo docker load -i nginx-stable-image.tar

Options

  • --input , -i: Specify image file name that will be loaded.

Examples

  • centos image example by using redirection
$ ls -al centos-centos7.5.1804-image.tar
-rw-rw-r-- 1 twpower twpower 207841280 Jul  4 22:55 centos-centos7.5.1804-image.tar
$ sudo docker load < centos-centos7.5.1804-image.tar
4826cdadf1ef: Loading layer  207.8MB/207.8MB
Loaded image: centos:centos7.5.1804
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              centos7.5.1804      cf49811e3cdb        3 months ago        200MB
  • nginx image example by using -i option
$ ls -al nginx-stable-image.tar
-rw------- 1 root root 113060352 Jul  4 22:56 nginx-stable-image.tar
$ sudo docker load -i nginx-stable-image.tar
da9fed87e1d3: Loading layer  54.59MB/54.59MB
0d1174230cc6: Loading layer  3.584kB/3.584kB
Loaded image: nginx:stable
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               stable              ac44715da54a        3 weeks ago         109MB
centos              centos7.5.1804      cf49811e3cdb        3 months ago        200MB


Reference