stackoverflow.comquestions23935141how-to-copy-docker-images-from-one-host-to-another-without-using-a-repository
stackoverflow.comquestions23935141how-to-copy-docker-images-from-one-host-to-another-without-using-a-repository
2163
How do I transfer a Docker image from one machine to another one without using a repository, no
matter private or public?
I create my own image in VirtualBox, and when it is finished I try to deploy to other machines to have
real usage.
Since it is based on my own based image ﴾like Red Hat Linux﴿, it cannot be recreated from a Dockerfile.
My dockerfile isn't easily portable.
docker
ShareImprove this questionFollow edited Mar 13, 2020 at 11:03 asked May 29, 2014 at 13:57
Software Engineer Larry Cai
15.4k 7 70 100 55.2k 34 110 154
2 Does this answer your question? How to save all Docker images and copy to another machine – Mišo Sep 2,
2020 at 7:59
There are ways to copy from one machine to another ‐ see the answer
stackoverflow.com/a/26226261/4329358 ﴾@kolypto﴿ below. However, gzip compression/decompression on
either end may cause more delays than transferring over Ethernet or WiFi. You can set up a private Docker
repository of your own which may speed up transferring images between machines. – Daisuke Aramaki Feb 1
at 21:06
Your privacy
Related discussions: stackoverflow.com/q/43274794/320399 , stackoverflow.com/q/58028894/320399, and
Bystackoverflow.com/q/58768032/320399 – blong
clicking “Accept all cookies”, you agree Apr 28 at 15:25
Stack Exchange can store cookies on your device and disclose
information in accordance with our Cookie Policy.
21 Answers
Accept all cookies Necessary cookies only Sorted by: Highest score ﴾default﴿
Customize settings
3503
Then copy your image to a new system with regular file transfer tools such as cp , scp , or rsync
﴾preferred for big files﴿. After that you will have to load the image into Docker:
You should add filename ﴾not just directory﴿ with ‐o, for example:
ShareImprove this answerFollow edited Mar 27 at 14:25 answered May 29, 2014 at 17:09
VLAZ ‐on strike‐ Daiwei
26k 9 49 65 40.1k 3 37 48
61 This is the better answer for images. – Andy May 29, 2014 at 20:18
74 also, it is better to use repo:tag as the image reference rather than image id . If you use image id , the
loaded image will not retain the tag ﴾and you will have to do another step to tag the image﴿. – wisbucky Sep
14, 2017 at 21:03
1 I used the image id instead of the name:tag Now I'm sitting here, loaded the image and have a <none> for
REPOSITORY and TAG. What is the right way to bring the name and tag back? @wisbucky – Ulfhetnar Jan 10,
2018 at 7:37
6 To tag, first identity the IMAGE ID using docker images , then use docker tag DESIREDIMAGEID
mycompany/myreponame . If your image id is 591de551d6e4, you can abbreviate the image id: docker tag 59
mycompany/myreponame – Junior Mayhé Aug 15, 2018 at 13:07
1 @serge not at all, it even has an example where a windows path is used... – Redoman May 5, 2021 at 11:27
851
Transferring a Docker image via SSH, bzipping the content on the fly:
Note that docker load automatically decompresses images for you. It supports gzip , bzip2 and xz .
It's also a good idea to put pv in the middle of the pipe to see how the transfer is going:
Use gzip / gunzip when your network is fast and you can upload at 10 Mb/s and more ‐‐ because
bzip won't be able to compress fast enough, gzip will be much faster ﴾Thanks @Thomas
Steinbach﴿
Use xz if you're on really slow network ﴾e.g. mobile internet﴿. xz offers a higher compression
ratio ﴾Thanks @jgmjgm﴿
ShareImprove this answerFollow edited Mar 14 at 21:59 answered Oct 6, 2014 at 23:11
kolypto
31k 17 103 97
25 When using docker‐machine, you can do docker $(docker‐machine config mach1) save <image> |
docker $(docker‐machine config mach2) load to copy images between machines mach1 and mach2.
– matlehmann Sep 4, 2015 at 12:57
5 @manojlds eval $(docker‐machine env dev) is good for general communication with a single docker host
but not to copy between two machines, since this involves two different docker hosts / docker machines.
– matlehmann Nov 18, 2015 at 15:47
27 to do this in reverse ﴾remote to local﴿: ssh target_server 'docker save image:latest | bzip2' | pv |
bunzip2 | docker load – ThorSummoner Feb 1, 2016 at 22:50
2 Is there any way to do this when docker requires sudo on the target machine? I tried ﴾without compression﴿
docker save my_img:v1 | ssh ‐t ‐t my_user@my_machine sudo docker load . Without the "‐t" switch,
sudo complains sudo: sorry, you must have a tty to run sudo; with one "‐t" it's the same message because ssh
says Pseudo‐terminal will not be allocated because stdin is not a terminal. and finally, with two "‐t"s, I get the
content of the tar file ﴾i.e. the image﴿ on my terminal. Any ideas? – hunger Dec 14, 2016 at 10:02
2 @JosefStark I needed to add "Defaults:<target username> !requiretty" when editing the sudoers file to stop
the "Sorry" message from sudo. I don't know how much of a difference it makes but I also put everything
the "Sorry" message from sudo. I don't know how much of a difference it makes but I also put everything
after the user@host in quotes ﴾so "[...] | ssh user@host 'bunzip2 | sudo docker load'"﴿. – VirtualWolf Jun 15,
2017 at 10:12
158
To save an image to any file path or shared NFS place see the following example.
docker images
Copy the image from the path to any host. Now import to your local Docker installation using:
ShareImprove this answerFollow edited Dec 30, 2020 at 13:43 answered Nov 4, 2014 at 5:54
Martti Laine Sohan
12.6k 22 68 102 6,132 5 35 56
88
13 This is definitely the command I was looking for, I think this answer deserves more love – Francois Jul 13, 2020
at 15:22
4 prereqs: ssh credentials setup on the remote ﴾ssh‐copy‐id﴿ and the local and remote user both need to be in
the docker group ﴾sudo usermod ‐aG docker $USER﴿ – GrendleM Nov 17, 2020 at 22:57
2 Are there any ﴾performance﴿ differences to ssh user@remotehost docker load here? – Mouagip Nov 10,
2021 at 14:11
2 @Mouagip I made a comparison between the two and this one ﴾ DOCKER_HOST=ssh://user@remotehost
docker load ﴿ seems to be a bit faster than ssh user@remotehost docker load . On my setup the difference
was about 5‐10 seconds on a process that took about 1 minute and 50 seconds. ﴾I timed both of the options
multiple times﴿ – Yarin Feb 22 at 14:02
70
docker save <docker image name> | gzip > <docker image name>.tar.gz
Then load the exported image to Docker using the below command:
ShareImprove this answerFollow edited May 25, 2021 at 7:04 answered Sep 27, 2016 at 4:33
Thorbjørn Ravn Damodaran
Andersen 10.8k 10 60 81
73.4k 33 191 346
32 For loading, docker load < my‐image.tar.gz is sufficient. The image gets decompressed automatically for
gzip, bzip2, and xz. – Flux Apr 4, 2018 at 2:41
48
Run
docker images
to see a list of the images on the host. Let's say you have an image called awesomesauce. In your
terminal, cd to the directory where you want to export the image to. Now run:
Copy the tar file to a thumb drive or whatever, and then copy it to the new host computer.
ShareImprove this answerFollow edited Aug 14, 2018 at 17:24 answered Nov 9, 2016 at 20:28
Peter Mortensen Neil Girardi
31k 21 104 131 4,465 1 26 42
9 Worth noting here is that this will only work if save and load are executed on the same OS. Use docker save
[image] ‐o file.tar and docker load ‐i file.tar to avoid this! – Andreas Forslöw Jun 11, 2019 at
14:52
docker save [image] ‐o file.tar also appears to be wildly faster – ti7 Feb 25, 2020 at 23:06
1 @AndreasForslöw Why does using pipes mean that this only works on the same OS?
– Thorbjørn Ravn Andersen May 25, 2021 at 7:05
32
The fastest way to save and load docker image through gzip command:
for example:
ShareImprove this answerFollow edited Jun 16, 2022 at 14:34 answered Mar 31, 2022 at 7:13
Tarek Kalaji
2,109 27 30
This is a great answer, and it works a treat, but do you have any idea how to get the container back? – Owl
Mar 18 at 19:03
28
ShareImprove this answerFollow edited Jan 7, 2016 at 14:32 answered May 29, 2014 at 14:19
vitaut Panagiotis Moustafellos
48.4k 25 190 330 963 1 8 17
10 it shall be cat my_container.tar | docker import ‐ my_container:new if import locally according to cmd
help – Larry Cai May 30, 2014 at 7:51
7 This is more for backing up a running container than for deploying an image. – Kousha Nov 25, 2014 at 3:49
I tried docker save at ubuntu machines which all docker images up and running good. Then i docker load
them at windows machine. There are many errors when i docker run or start them. Any ideas whats wrong?
– user2201789 Nov 16, 2021 at 12:29
this does not work on windows command prompt or powershell directly because there is no *.tgz support to
load package, you may need to install packages and change the command on windows – Tarek Kalaji Mar 20
at 15:20
25
It sets up a temporary private Docker registry on the server, establishes an SSH tunnel from your
localhost, pushes your image, then cleans up after itself.
The benefit of this approach over docker save ﴾at the time of writing most answers are using this
method﴿ is that only the new layers are pushed to the server, resulting in a MUCH quicker upload.
https://github.com/brthor/docker‐push‐ssh
Install:
Example:
The biggest caveat is that you have to manually add your localhost to Docker's insecure_registries
configuration. Run the tool once and it will give you an informative error:
ShareImprove this answerFollow edited Jul 29, 2019 at 13:54 answered Sep 12, 2018 at 5:20
Louis brthornbury
146k 28 273 318 3,498 1 22 21
This is a promising utility. Do any other answers offer a solution which copies only the updated layers? But, I
had to work through a﴿ no py3 support, b﴿ ssh identify file must be specified though mine is in default
location, and c﴿ port 5000 is already in use on my servers and there is no option to change to another port.
– nmgeek Mar 4, 2021 at 0:09
@nmgeek Consider making a PR to the utility on GitHub so others can benefit from your changes.
– brthornbury Mar 5, 2021 at 22:15
18
When using docker‐machine, you can copy images between machines mach1 and mach2 with:
docker $(docker‐machine config <mach1>) save <image> | docker $(docker‐machine config <mach2>) load
And of course you can also stick pv in the middle to get a progess indicator:
docker $(docker‐machine config <mach1>) save <image> | pv | docker $(docker‐machine config <mach2>)
load
You may also omit one of the docker‐machine config sub‐shells, to use your current default docker‐
host.
or
ShareImprove this answerFollow edited Apr 12, 2019 at 3:01 answered Oct 14, 2016 at 9:53
John Kugelman matlehmann
347k 67 524 574 382 3 8
16
Save the archiveName image to a tar file. I will use the /media/sf_docker_vm/ to save the image.
Copy the archiveName.tar file to your new Docker instance using whatever method works in your
environment, for example FTP , SCP , etc.
Run the docker load command on your new Docker instance and specify the location of the image tar
file.
Finally, run the docker images command to check that the image is now available.
ShareImprove this answerFollow edited Aug 14, 2018 at 17:14 answered Sep 29, 2014 at 5:25
Peter Mortensen tk_
31k 21 104 131 16.3k 8 80 90
16
Above code will save all the images in allimages.tar and to load the images go to the directory where
you saved the images and run this command :
Just make sure to use this commands in PowerShell and not in Commad Prompt
ShareImprove this answerFollow edited Dec 18, 2022 at 6:51 answered Apr 16, 2022 at 5:55
Kaveh Naseri
1,002 2 15 24
14
#host1
systemctl stop docker
systemctl start docker
docker commit ‐p 1d09068ef111 ubuntu001_bkp3
#create backup
docker save ‐o ubuntu001_bkp3.tar ubuntu001_bkp3
#host2
systemctl stop docker
systemctl start docker
cd /dir1
#download ubuntu001_bkp3.tar from my online drive
aws s3 cp s3://mybucket001/ubuntu001_bkp3.tar /dir1
#restore backup
cat ./ubuntu001_bkp3.tar | docker load
docker run ‐‐name ubuntu001 ‐it ubuntu001_bkp3:latest bash
docker ps ‐a
docker attach ubuntu001
ShareImprove this answerFollow edited Oct 18, 2021 at 2:46 answered Jul 12, 2021 at 0:42
quine9997
615 6 9
3 Why are you stopping docker service before you do anything? – Will Huang Jul 16, 2021 at 14:39
it's not working for me !! Getting this error ‐‐‐ > 'open /var/lib/docker/tmp/docker‐import‐
315206241/app/json: no such file or directory' – santosh verma Dec 14, 2021 at 11:36
12
ShareImprove this answerFollow edited Aug 14, 2018 at 18:01 answered May 26, 2017 at 17:25
Peter Mortensen Bryan Larsen
31k 21 104 131 9,396 8 55 45
All other answers are very helpful. I just went through the same problem and figure out an easy way
with .
with docker machine scp .
Since Docker Machine v0.3.0, scp was introduced to copy files from one Docker machine to another.
This is very convenient if you want copying a file from your local computer to a remote Docker
machine such as AWS EC2 or Digital Ocean because Docker Machine is taking care of SSH credentials
for you.
Assume your remote Docker machine is remote‐machine and the directory you want the tar file to be is
/home/ubuntu .
ShareImprove this answerFollow edited Aug 14, 2018 at 17:20 answered Feb 9, 2016 at 3:21
Peter Mortensen Peng
31k 21 104 131 434 5 14
9 why not just 'scp <source> <remote>' ? – Tamas Kalman May 31, 2017 at 1:11
If you are working on a Windows machine and uploading to a linux machine commands such as
will not work if you are using powershell as it seems that it adds an additional character to the output.
If you run the command using cmd ﴾Command Prompt﴿ it will however work. As a side note you can
also install gzip using Chocolatey and the following will also work from cmd.
Based on the @kolypto 's answer, this worked great for me but only with sudo for docker load:
This is because your user is not a member of the "docker" group :﴿ Don't do sudo; just do this once: sudo
adduser $USER docker – kolypto Jun 1 at 22:00
```
OUT=$(docker images ‐‐format '{{.Repository}}:{{.Tag}}')
OUTPUT=($OUT)
docker save $(echo "${OUTPUT[*]}") ‐o /dir/images.tar
```
```
Explanation:
First OUT gets all tags but separated with new lines. Second OUTPUT gets all tags in an array. Third
$(echo "${OUTPUT[*]}") puts all tags for a single docker save command so that all images are in a
single tar.
‐O option to tar puts contents on stdin which can be grabbed by docker load .
For example:
Script to perform Docker save and load function ﴾tried and tested﴿:
Docker Save:
#!/bin/bash
#!/bin/bash
cd Docker_images/
directory=`pwd`
ls | grep tar > files.txt
c=0
printf "START \n"
input="$directory/files.txt"
while IFS= read ‐r line
do
c=$((c+1))
printf "$c) $line \n"
docker load ‐i $line
printf "$c) Successfully created the Docker image $line \n \n"
done < "$input"
Highly active question. Earn 10 reputation ﴾not counting the association bonus﴿ in order to answer this
question. The reputation requirement helps protect this question from spam and non‐answer activity.