Export and Import a Docker Image Between Nodes

Export and Import a Docker Image Between Nodes

Get Social!

docker-logoOne of the driving forces behind Docker is to create a consistent environment across all Docker enabled machines and to create portable templates, or images, which can be ran on any Docker enabled server.

It would, therefore, make perfect sense that Docker have made it very easy for us to export a running container and re-import it on another Docker server.

Lets assume, for this example, that you have a running container that you would like to move to another host. The summary of the process is to save the container to an image, save it to a tar file, move it to your new host and load the image into the new docker server.

Find the ID of the container that you would like to move.

I’m going to use the above 3a09b2588478 ID for this example.

Commit your changes and save the container to an image called mynewimage.

Save the mynewimage image to a tar file. I will use the /tmp/ directory to save the image but you could easily use a NFS share to make it easier to move the completed tar file.

Copy the mynewimage.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.


12 Comments

Luc

5-Sep-2014 at 3:34 pm

Thanks for this tutorial, this is exactly what I needed.

Nico

10-Sep-2014 at 6:24 am

How to load an image with preserving it’s repository and tag name?

    Alex Glover

    8-Jan-2015 at 4:48 pm

    If you use the “docker save” command, repository and tag name should be stored as part of the tar file. When you execute “docker load” it should retain the repo and tag name.

Thomas

11-Mar-2015 at 2:16 pm

Hey!

Thank you very much for this tutorial. I have one problem, you may know to solve. I have two hosts with fresh docker installations. On host A is a running container with changes, so I commited and saved it along your tutorial, copied to host B and do “docker load < /tmp/whatever.tar". After that it seems it doing something and finishing. Run "docker ps -a" afterwards, nothing is listed. Indeed there isn't any image or container on host B before! What can I do?

    Brad

    13-Mar-2015 at 10:07 pm

    “docker load” creates an image, not a container. “docker ps -a” will show all containers, not images. “docker images” should show you the image you created with “docker load”.

twodayslate

15-Oct-2015 at 5:07 pm

If you don’t want to use STDIN/STDOUT use the following:

docker save -o ~/image.tar
docker load -i ~/image.tar

buriz

19-Nov-2015 at 3:07 pm

We have a problem when saving docker images and loading them on another machine (running the same OS – CoreOS) not all files are the same. Some symlinks are lost within apache directory.

1. $ docker commit [container ID] [image_name]
2. $ docker save > [image_name].tar
3. Copying the image on another machine running exactly the same OS (In fact it is a cloned VM, so it is exactly the same).
4. $ docker load < [image_name].tar
5. $ docker run –name [container_name] –link [link_wordpress_to_db]:mysql -e WORDPRESS_DB_USER=[user] -e WORDPRESS_DB_PASSWORD=[pass] -e WORDPRESS_DB_NAME=[db_name] -p 8080:80 -d [image_name]

For some reason saving and loading the image does not retain the symlinks from /var/www/html properly. Even their ownership is still www-data, although in the original container they are owned by root and [wp-user].

varaprasad

25-Feb-2016 at 9:44 am

what is the different between EXPORT and SAVE

Pratik Bandarkar

24-Feb-2017 at 11:43 am

What is the use of `docker export/import` ?

Rajesh

7-Mar-2017 at 4:03 am

Thanks for your tutrorial.I have learned how to do it.Thanks

Harshul

23-Aug-2017 at 4:09 am

Very clean and crisp tutorial. Thank you!

babuni

14-May-2018 at 1:37 pm

How to add more Images on same existing file???

Leave a Reply