Bobcares

How to export and import containers with Docker?

by | Oct 19, 2020

Users may often require to move Docker containers from one host to another. Docker export and import tools come in handy here to perform the movement of containers

As a part of our Docker Hosting Support, we help our Customers with Docker related requests regularly.

Let us today discuss the steps to export and import Docker containers.

 

Why do we need export and import containers with Docker?

A move of Docker containers from one host to another would be required in a number of scenarios. This may be required in case of a Docker server starting to fail or if we want to migrate the containers to more powerful hardware.

For this, we could push the image they were based on to Docker Hub, pull the image down, and rebuild the container. Another method would be to simply export the container, move the exported file to the machine in question, and import that container.
 

Exporting a container

The first thing we need to do is to list out the containers. For this, we need to know the names of those containers. To do this, issue the command below:

docker ps -a

The NAME column in the output lists the names that can be useful for exporting.

docker export and import containers

For ease of transport, we will be exporting the containers into a gzipped file. The command to export the containers is:

docker export NAME | gzip > NAME.gz

Where NAME is the name of the container to be exported. We are now ready to relocate the file and import it.
 

Importing a container

Similar to the export command used earlier, we can import the container with a single command. First, move the exported file to the new server. You could do this using the SCP command like the one below:

scp NAME.gz USERNAME@SERVER_IP:/home/USERNAME

Where NAME is the file name, USERNAME is the user name on the remote server and SERVER_IP is the IP address of the remote server.

Once we have done that, the import can be handled with the following command:

zcat NAME.gz | docker import - NAME

Where NAME is the name of the container. We can now run the newly imported container with a command similar to the one below:

docker run -i -t NAME /bin/bash

Where NAME is the name of the container.

After importing exit from the container using the command exit.

[Need any further assistance to export and import Docker containers? – We’re available 24*7]

Conclusion

In short, Docker export and import tools come handy to move a container from host to host. Today, we saw how our Support Engineers export and import Docker containers

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.