How do I transfer a Docker image from one machine to another one without using a repository? Is the repository is mandatory to transfer the image between hosts? No. We can simply save the docker image as a tarball and transfer it to the remote host. You can import the docker image from the tar ball on the remote host to start the container again. This is a peculiar use case where you will not have access to public repositories.
Use case scenarios:
- Unable to pull the docker image from the public repository (Ex: docker hub, quay.io ).
- The image is on the docker host where you do not have private artifactory to upload and share. (Ex: JFrog)
How to save the container image as tarball ?
1. Login to the linux host which has the connectivy to pull the image from the source. In this case, I am pulling the image from quay.io. For an example , I have pulled “argocd-applicationset” docker image.
[root@okd4 ~]# docker pull quay.io/argoproj/argocd-applicationset Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. Trying to pull quay.io/argoproj/argocd-applicationset:latest... Getting image source signatures Copying blob 6f172cdbcbef done Copying blob 1c776846e345 done Copying blob 97ae2f7f1aaa done Copying blob a7daf021a15e done Copying blob 542f216aea60 done Copying blob 993b36209f1f done Copying blob fe80e96c702e done Copying blob 7b2b61b3981a done Copying blob 821c1db65a47 done Copying blob 461ac99d8b36 done Copying config 1459f7c87d done Writing manifest to image destination Storing signatures 1459f7c87d7b68c8e20625d2158c84f29a7f408db5cb6d4fe91dbb44c7d04741
2. List the docker image and save the docker image as tarball using image id.
[root@okd4 ~]# docker images Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. REPOSITORY TAG IMAGE ID CREATED SIZE quay.io/argoproj/argocd-applicationset latest 1459f7c87d7b 4 weeks ago 253 MB [root@okd4 ~]# docker save -o argocd-applicationset.v0.4.1.tar 1459f7c87d7b Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. Copying blob dca6a631e9bb done Copying blob 68c6f20e35a3 done Copying blob 52bd696d96d5 done Copying blob c3c1e5fa07a4 done Copying blob fdfb3dc7e72a done Copying blob 945f8669d40b done Copying blob b570dbd22736 done Copying blob 385ceda47926 done Copying blob dc646e9d17d7 done Copying blob 3556bed2dc7d done Copying config 1459f7c87d done Writing manifest to image destination Storing signatures [root@okd4 ~]# total 246756 -rw-------. 1 root root 1034 Mar 18 19:24 anaconda-ks.cfg -rw-r--r--. 1 root root 252672512 Mar 21 11:12 argocd-applicationset.v0.4.1.tar [root@okd4 ~]#
3. You can transfer the generated tarball to the desired host where you want the container to be started. To transfer between Linux hosts, you can use “scp”. If you want to transfer to windows, use “winscp”.
How to import the container image from tarball ?
1. Login to the host where you have copied the tarball to import it .
3. List the docker images.
[root@okd5 ~]# docker images Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. REPOSITORY TAG IMAGE ID CREATED SIZE [root@okd5 ~]#
3. List the files and use docker load command to import the docker image.
[root@okd5 ~]# ls -lrt total 246756 -rw-r--r--. 1 root root 252672512 Mar 21 12:12 argocd-applicationset.v0.4.1.tar [root@okd5 ~]# docker load -i argocd-applicationset.v0.4.1.tar Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. Getting image source signatures Copying blob 945f8669d40b done Copying blob 68c6f20e35a3 done Copying blob dca6a631e9bb done Copying blob c3c1e5fa07a4 done Copying blob 52bd696d96d5 done Copying blob fdfb3dc7e72a done Copying blob b570dbd22736 done Copying blob 385ceda47926 done Copying blob 3556bed2dc7d done Copying blob dc646e9d17d7 done Copying config 1459f7c87d done Writing manifest to image destination Storing signatures Loaded image(s): sha256:1459f7c87d7b68c8e20625d2158c84f29a7f408db5cb6d4fe91dbb44c7d04741 [root@okd5 ~]#
4. List the docker image again.
[root@okd5 ~]# docker images Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 1459f7c87d7b 4 weeks ago 253 MB [root@okd5 ~]#
We have successfully imported the docker image from the tarball.
Leave a Reply