Export/Import Docker Container Image to File

Maciej
2 min readJul 23, 2021
Photo by Ian Taylor on Unsplash

Generally, the container image is used by pulling the one pushed to the container registry . There is also a method of exchanging container images as files without going through the above registry.

Export the container image to a file

You can export it to a tar file with a command.

root@vagrant:/home/vagrant# docker pull spy86/sonarqube:latest
latest: Pulling from spy86/sonarqube
d960726af2be: Pull complete
e8d62473a22d: Pull complete
8962bc0fad55: Pull complete
65d943ee54c1: Pull complete
da20b77f10ac: Pull complete
fb6a778e6477: Pull complete
ae7884f0e61b: Pull complete
5d6c92be81fd: Pull complete
f5c36a6a2e0b: Pull complete
f8d500468a7d: Pull complete
Digest: sha256:6186a5d978653c08c7e7dd6e44da5e72e7dbe9ab0854c0d8241e0b5382c7b667
Status: Downloaded newer image for spy86/sonarqube:latest
docker.io/spy86/sonarqube:latest
root@vagrant:/home/vagrant# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
spy86/sonarqube latest 3d292a51eff7 8 weeks ago 763MB
root@vagrant:/home/vagrant# docker save spy86/sonarqube:latest > sonarqube.tar
root@vagrant:/home/vagrant# ls -laht | grep sonarqube
-rw-r--r-- 1 root root 741M Jul 20 17:54 sonarqube.tar

Import container image from file

First we will clean all images

root@vagrant:/home/vagrant# docker system prune --all --force
Deleted Images:
untagged: spy86/sonarqube:latest
untagged: spy86/sonarqube@sha256:6186a5d978653c08c7e7dd6e44da5e72e7dbe9ab0854c0d8241e0b5382c7b667
deleted: sha256:3d292a51eff7b33f96a80180bbedcebc53a2dd31c2ca84a0804254b49aab3066
deleted: sha256:e137ead274bf8ec01bf8de25bcb1196f0196e76f774a7ff87265df3cc5bb08f0
deleted: sha256:9221faebc332f4f5da0dba7c783e5de13f023964618920a2e551948a402c9845
deleted: sha256:4c46b90ed684695a4d3444959012f8757e44e5e7add2c968f5ab406da9b610c5
deleted: sha256:a1ebb61f926c6adb4be953d5fa465ad632e0f280d666290131c40402869da050
deleted: sha256:8322a18d091807c0b67edd4c8b80a8302e55c538427a5350e626f13fe111553b
deleted: sha256:7d9015a7e7cc4ffda4712793436cecdd5572df6e80ee67912a76a6442c448b2d
deleted: sha256:1405602eb1a912ad0bef3b35fc79f4a1eb332cd3ff05b36b560dad11e8d8ca7f
deleted: sha256:1a126caa7f2df8ccb95a4a08242b527fe3268eebf55cdd72b5b6a7aafd908519
deleted: sha256:b639806ab48953fe53941bccbaaecc99d82e693585e7b818ff9a6413ef519f25
deleted: sha256:688e187d6c79c46e8261890f0010fd5d178b8faa178959b0b46b2635aa1eeff3
Total reclaimed space: 762.8MB
root@vagrant:/home/vagrant#

Now we can import from a tar file with a command.

root@vagrant:/home/vagrant# docker load < sonarqube.tar
688e187d6c79: Loading layer [==================================================>] 119.3MB/119.3MB
00bcea93703b: Loading layer [==================================================>] 17.18MB/17.18MB
ccb9b68523fd: Loading layer [==================================================>] 17.87MB/17.87MB
685934357c89: Loading layer [==================================================>] 150MB/150MB
3fc095fab4a2: Loading layer [==================================================>] 11.54MB/11.54MB
4a64f1e3a7a1: Loading layer [==================================================>] 3.584kB/3.584kB
bd87f5884754: Loading layer [==================================================>] 209.8MB/209.8MB
23eb022d1419: Loading layer [==================================================>] 338.4kB/338.4kB
79abcc29e6fe: Loading layer [==================================================>] 250MB/250MB
2196f0b7ddc7: Loading layer [==================================================>] 3.584kB/3.584kB
Loaded image: spy86/sonarqube:latest
root@vagrant:/home/vagrant# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
spy86/sonarqube latest 3d292a51eff7 8 weeks ago 763MB
Source: https://giphy.com/

--

--

Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.