- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to copy Docker images from one host to another without using a repository?
If you have a Docker image in your own local machine and you want that image to be copied into another machine, there are two ways to do that. The first is by pushing that image to a repository such as the ones in Dockerhub registry. You need to have an account in Dockerhub and then you can use the Docker push command to push the images on it.
However, if you don’t want to go through all the hassles of creating an account, tagging the images, etc., there are other simple methods that you can use. Let’s check out all such methods in this article.
Method 1. Saving and Loading the Image from TAR files
Docker allows you to save images into tar files using the Docker save command. This will also compress the entire image and will allow you to share them easily and quickly. You can then use the Docker load command in another machine to load the Docker image back from the tar file. The commands to do so are -
$ docker save -o <tar file path in source host machine> <image name>
You can then copy this tar file using simple tools such as cp, rsync, scp, etc. or any other method that you prefer. Next, you can use the Docker load command to restore the image from this tar file.
$ docker load -i <path to image tar file>
Method 2. Copy Docker Images Via SSH
You can also transfer your Docker images through SSH and bzip the content to compress it on the fly. The command to do so is -
$ docker save <image> | bzip2 | \ ssh user@host 'bunzip2 | docker load'
If you want to check how the transfer is taking place, you can use the pv through the pipe.
$ docker save <image> | bzip2 | pv | \ ssh user@host 'bunzip2 | docker load'
Method 3. Copying Docker Images using Docker Machines
If you have two Docker machines - machine1 and machine2, you can copy the images using the following command.
$ docker $(docker-machine config machine1) save <image> | docker $(docker-machine config machine2) load
Method 4. Copying Images Using DOCKER_HOST variable
You can also use the DOCKER_HOST variable to copy images from one host to another. You will need the SSH credentials and both the users on the local and remote machines should be in the Docker group.
$ docker save <image name>:<tag-name> | gzip | DOCKER_HOST=ssh://user@remotehost docker load
Method 5. Use Docker-push-ssh to copy images
You have another command-line utility called docker-push-ssh. It will help you to set up a private Docker registry which is temporary on the host server. It will then create an SSH tunnel from the localhost. Next, it will push the Docker image and automatically clean up.
The advantage of using this method instead of the docker save command is that in this case only the new layers are always pushed to the server. This results in a faster upload.
To do so, you will have to first install docker-push-ssh using the following pip command.
$ pip install docker-push-ssh
You can then use the one-line to push the image.
$ docker-push-ssh -i ~/your-ssh-key firstname.lastname@example.org <docker-image>
Method 6. Transferring Image using Docker Machine Scp
The Docker Machine scp was created to copy or transfer files from a particular Docker machine to another. It becomes extremely convenient in case you want to copy images from the local machine to a remote Docker machine on cloud such as AWS or Digital Ocean. This is so because the Docker Machine will automatically take care of the SSH credentials.
To do so, you can follow these steps -
- Use Docker save command.
$ docker save -o <tar-file-location> <image name>
- Transfer Docker Images using docker machine scp.
$ docker-machine scp ./image-tar.tar target-machine:/home/ubuntu
Here, target-machine is the name of the remote machine, /home/ubuntu is the target location, and image-tar is the name of the tar file.
- Load the tar file.
$ docker-machine ssh target-machine sudo docker load -i image-tar.tar
To sum up, in this article, we discussed 6 different methods using which you can copy or transfer Docker images from one local machine to another remote machine without the use of any Docker registry or repository. As per your convenience and requirements, you can easily use any of the discussed methods.
- Related Articles
- How to copy files from host to Docker container?
- How to save all Docker images and copy to another machine?
- How to run amd64 Docker images on the arm64 host platform?
- How to copy files from one folder to another using Python?
- How to copy files from one server to another using Python?
- How can I copy a file from one folder to another folder within a container in Docker?
- How to copy certain files from one folder to another using Python?
- How to copy items from one location to another location using PowerShell?
- How to copy a table from one MySQL database to another?
- Copying files from Docker container to Host
- How to copy a collection from one database to another in MongoDB?
- How to copy rows from one table to another in MySQL?
- How to copy the palette from one image to another using imagepalettecopy() function in PHP?
- Connecting From Docker Containers to Resources in Host
- How to copy from clipboard using tkinter without displaying a window