DOCKER SAVE vs DOCKER LOAD

In the article, we are going to learn about the usage of docker save and docker load.

Docker save is the comment used to save one or more images to a tar file

Let’s pull some images first.

ubuntu@ip:~/test$ docker pull centos 
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
ubuntu@ip:~/test$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
405f018f9d1d: Pull complete 
Digest: sha256:b6b83d3c331794420340093eb706a6f152d9c1fa51b262d9bf34594887c2c7ac
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
ubuntu@ip:~/test$ docker images ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
ubuntu@ip-172-31-95-249:~/test$ docker images 
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
ubuntu       latest    27941809078c   3 weeks ago    77.8MB
centos       latest    5d0da3dc9764   9 months ago   231MB

Let’s try docker save to save the images to a tar archive

ubuntu@ip:~/test$ docker save ubuntu centos > os.tar.gz
ubuntu@ip:~/test$ ls
os.tar.gz

Let’s remove the unused images

ubuntu@ip:~/test$ 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:
untagged: ubuntu:latest
untagged: ubuntu@sha256:b6b83d3c331794420340093eb706a6f152d9c1fa51b262d9bf34594887c2c7ac
deleted: sha256:27941809078cc9b2802deb2b0bb6feed6c236cde01e487f200e24653533701ee
deleted: sha256:a790f937a6aea2600982de54a5fb995c681dd74f26968d6b74286e06839e4fb3
untagged: centos:latest
untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6
deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59

Total reclaimed space: 309.1MB

Now no active images are left.

ubuntu@ip:~/test$ docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

Let’s try docker load to pull the images from the tar file.

ubuntu@ip:~/test$ docker load < os.tar.gz 
74ddd0ec08fa: Loading layer [==================================================>]  238.6MB/238.6MB
Loaded image: centos:latest
a790f937a6ae: Loading layer [==================================================>]  80.34MB/80.34MB
Loaded image: ubuntu:latest

We can use docker images to view the available images

ubuntu@ip:~/test$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
ubuntu       latest    27941809078c   3 weeks ago    77.8MB
centos       latest    5d0da3dc9764   9 months ago   231MB

Post navigation

Leave a Reply