Lets learn "How to transport docker images from one host to another"
In this tutorial, we'll learn about how to transport/send a docker image from one host to another.
1. Use shared docker registry
One way is to use the shared docker registry between the hosts. Like in the below example if we wanna share a docker image built on HOST1 to HOST2. After building the image (<IMAGE-NAME>:<TAG>) on HOST1, Run the below commands to push it to the shared registry.
ON HOST1, publish the docker image
docker tag <IMAGE-NAME>: <TAG> <REGISTRY-ADDRESS>/<IMAGE-NAME>:<TAG>
docker push <REGISTRY-ADDRESS>/<IMAGE-NAME>:<TAG>
ON HOST2, pull the docker image
docker pull <REGISTRY-ADDRESS>/<IMAGE-NAME>:<TAG>
2. Create an image file and SCP to the target host
This way requires to convert the docker image to a file. After the image is converted to file, it can be transported to other hosts where it can be loaded back to its own docker registry. This method emilinates one hop of shared docker registry. Like previous example if from HOST1 we wanna transport to HOST2.
ON HOST1, create a docker image file
docker build -f <pathToDockerfile> -t <IMAGE-NAME>:<TAG>
docker save <IMAGE-NAME>:<TAG> | gzip >> <IMAGE-NAME>.tar.gz
scp <IMAGE-NAME>.tar.gz <USER>@HOST2:<DESTINATION-PATH>/
ON HOST2, load the docker image
docker load -i <DESTINATION-PATH>/<IMAGE-NAME>.tar.gz
That's it! Hope you like the tutorial. Please provide your feedback in the comments below. Stay tuned for the new tutorials ;)
Comments
Post a Comment