How to save and restore your docker image locally?

Every been in a situation where you have no access to an artifactory to store and retrieve docker images from? Maybe for those classified projects for which you cannot afford to have logic or code stored online? This blog post shows you how you can save your images locally, and also restore them. 

In order to save a docker image locally, you will need to use the docker save command. This will generate a tarball the image that you specify. See below. 


mukul@mukul-dev-vm:~$ docker image ls
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
qca-python              latest              f6d5713920ab        21 hours ago        1.03GB
old-db                  latest              c2cf969a8e83        43 hours ago        297MB
postgres                <none>              131ab388dac1        8 days ago          200MB
jenkins-blueocean       latest              7dfc5120d1b3        2 weeks ago         1.09GB
python                  3                   1b33974176a3        3 weeks ago         886MB
python                  latest              1b33974176a3        3 weeks ago         886MB
jenkins/jenkins         2.289.3-lts-jdk11   ea470c80c15d        3 weeks ago         680MB
testbed_ui_app_dev      latest              875e9ba5520a        6 weeks ago         769MB
qca-schema-db           latest              6df2ee35b15b        6 weeks ago         297MB
mumanika/test_machine   1                   d481f0b6c1cc        8 weeks ago         466MB
postgres                9.6                 3bd014396ae0        2 months ago        200MB
hello-world             latest              d1165f221234        5 months ago        13.3kB
centos                  centos8             300e315adb2f        8 months ago        209MB
ruby                    2.2                 6c8e6f9667b2        3 years ago         715MB
ruby                    2.2.5-slim          2ddf5f283a22        4 years ago         270MB

mukul@mukul-dev-vm:~$ docker save mumanika/test_machine > test-save.tar

If you want to restore this image on a machine that is isolated from the internet, you will need to transfer this tar file to that machine and then run the following command.


meukul@mukul-dev-vm:~$ docker load -i test-save.tar
66edeb4546d5: Loading layer [==================================================>]  261.5MB/261.5MB
538d04b00012: Loading layer [==================================================>]  1.536kB/1.536kB
7eee7994848d: Loading layer [==================================================>]  334.3kB/334.3kB
d99130ae9368: Loading layer [==================================================>]    194kB/194kB
Loaded image: mumanika/test_machine:1

Reference Documentation: https://docs.docker.com/engine/reference/commandline/save/

Simple, right? Hope this helps! ☺️

Previous
Previous

How to manage your docker containers as a non-root user?

Next
Next

Do you know what DEBIAN_FRONTEND=noninteractive in a Dockerfile means?