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:
- docker save : Saves an image and all its history
- docker load: Loads an image exported with docker save
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.