Generally for running a docker container we first pull the required docker image/s from a container registry(CR), for ex- Github container registry, Docker Hub registry etc. This could be a publicly available image or a private one. Similarly we can push a newly built image to these registries.
But what if we want to share an image that is currently stored in one machine to another machine or server without using a container registry.
For this solution to work we need a shared storage or access to a cloud location or a file transfer capability between two machines(ex: SCP).
Steps to share a Docker image:
A. On first machine, build a new docker image or pull one from a container registry.
B. Once the image is ready on first machine, save it in a .tar file in the local storage:
docker save -o <location-1>/image-name.tar image-name
C. Check if the new .tar file is saved in your local storage(location-1):
ls <location-1>
D. Share this newly created .tar file to a location which is accessible by second machine. This could be a Cloud storage location on Azure, AWS etc, or a shared directory or simply 'scp' the file if its in a same network.
E. Now save the new .tar file in of second machine.
Once the file is available on second machine we will load the image from that .tar file using below command:
docker load -i <location-2>/image-name.tar
F. We can now check if the image is now available in the second machine:
docker images
G. Now the image has been transferred successfully in your second machine without even using any container registry.
This method works for both Linux and Windows based machines.
Check official Docker documentation for more information.
Ref:
https://docs.docker.com/engine/reference/commandline/save/
https://docs.docker.com/engine/reference/commandline/load/
https://docs.docker.com/engine/reference/commandline/export/
https://docs.docker.com/engine/reference/commandline/import/
Top comments (0)