Import and Export Docker Containers

In cases where you cannot for whatever reason build docker containers on your local system, do not fear. Docker allows you to save and import backed up images of containers.

Saving Containers

It is a good habit to routinely save containers. Just open a terminal and use the docker save command. Example here:

docker save -o ~/Desktop/my_docker_image.tar laravel

Once that is saved you can share it with other developers or keep it as a personal backup. 

Restoring from a Container Image

If one of your containers is acting wonky, you can get the name and image id with the following command:

docker images

docker image rm IDOFBADCONTAINER

Now you can load a new container to replace the broken one.  To do this you will need to get an image from another developer or use one you previously saved. 

To load the container from the image use the docker load command. Example here:

docker load -i ~/Desktop/my_docker_image.tar

Post navigation

Leave a Reply

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