Exporting Docker images

Sometimes you want to move docker images from one machine to another and you don’t have a proper docker registry or it is not availabe.

Docker provides commands for that:

But these images can be really big in size, there is an alternative to save only the current container, no the image with all its historic data.

What we are going to do is export a running container with the command docker export:

docker export my_container > docker-container.tar

This will export the container as it is, without the metadata contained in CMD or ENTRIPOINT tags.
We can import it again with docker import:

docker import docker-container.tar mydockers/my_container:v1

But we can also restore the CMD tag with:

docker import --change 'CMD ["nginx","-g","daemon off;"]' docker-container.tar mydockers/my_container:v1

In this case we are rewriting the CMD tag, so when we execute:

docker run -ti mydockers/my_container:v1

The CMD command will be executed, in this case it is the nginx server.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s