Backup a running Docker container?

LinuxDockerLinux Containers

Linux Problem Overview


Is it possible to backup a running Docker container? Is the export command suitable for doing that?

Linux Solutions


Solution 1 - Linux

Posted by one friend in comments

Hi Slava, sorry that your question was closed. For the record, Slava is talking about docker.io, a runtime for linux containers. Yes, docker export is a suitable approach. It will generate a tarball of your entire container filesystem state, and dump it on stdout. So

docker export $CONTAINER_ID > $CONTAINER_ID-backup.tar

will yield a usable tarball. You can re-import the tarball with

docker import - slava/$CONTAINER_ID-backup < $CONTAINER_ID-backup.tar

Note the original metadata (eg id of the original image) will be lost. This should be fixed in future versions of docker. ā€“ Solomon Hykes Apr 2 '13 at 6:35

Adding here so one can find from summary that question was answered. Thanks Solomon!

Solution 2 - Linux

export has some limitations: it won't export the data volume.

Here's data volume means:

  1. There's a VOLUME defined in the image's Dockerfile.
  2. The container is start with a parameter like this: -v /webapp

More about data: https://docs.docker.com/userguide/dockervolumes/

The way to handle this situation is start a new container with '--volumes-from' parameter to hook on that container, so you can visit the data volume.

Examples:

  1. Visit the data: (in a bash)
  1. Backup to host: (a postgres container)

Solution 3 - Linux

Using the docker commit is my preferred way to back up a container (started or stopped). Creates an image that you can name:

docker commit - p <container_id> <backup-name>

Solution 4 - Linux

you can also using save and load.. here's the sample

  1. sudo docker images

     awan@google-dev:~/StarCenter/_docker$ sudo docker images
     REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
     google_star/_version_1.10           latest              1067d6689697b2        4 days ago          1.666 GB
    
  2. sudo docker save google_star/_version_1.10 > my_docker-backup.tgz

  3. restore it using (sudo docker load < my_docker-backup.tgz)

  4. check your images using sudo docker images in your new docker machine

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSlava VView Question on Stackoverflow
Solution 1 - LinuxJuliandotNutView Answer on Stackoverflow
Solution 2 - Linuxsemicircle21View Answer on Stackoverflow
Solution 3 - LinuxBrian OgdenView Answer on Stackoverflow
Solution 4 - LinuxAwanView Answer on Stackoverflow