Bobcares

How to export and import containers with Docker?

PDF Header PDF Footer

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 -aCopy Code

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.gzCopy Code

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/USERNAMECopy Code

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 - NAMECopy Code

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/bashCopy Code

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

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

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

0 Comments

Submit a Comment

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

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Docker Support

Spend time on your business, not on your servers.

Managing a server is time consuming. Whether you are an expert or a newbie, that is time you could use to focus on your product or service. Leave your server management to us, and use that time to focus on the growth and success of your business.

TALK TO US Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!