Is it possible to backup a running Docker container? Is the export command suitable for doing that?
-
16Hi 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– Solomon Hykes2013-04-02 06:35:06 +00:00Commented Apr 2, 2013 at 6:35
-
4@SolomonHykes One more clarification - will it yield a LVM-snapshot-like tarball or just a regular tarball with data changing during the tar?Slava V– Slava V2013-04-02 08:40:16 +00:00Commented Apr 2, 2013 at 8:40
-
Also have a look at github.com/dotcloud/docker/issues/2116 , part of the issue is discussed thereUli Köhler– Uli Köhler2014-01-04 18:13:24 +00:00Commented Jan 4, 2014 at 18:13
-
Also take a look at my answer to a related question: stackoverflow.com/questions/27288070/…RoyB– RoyB2015-01-07 09:48:34 +00:00Commented Jan 7, 2015 at 9:48
4 Answers
Posted by one friend in comments (Solomon Hykes Apr 2 '13 at 6:35):
Hi Slava, sorry that your question was closed. For the record, Slava is talking about docker.io, a runtime for linux containers. Yes,
docker exportis 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.tarwill yield a usable tarball. You can re-import the tarball with
docker import - slava/$CONTAINER_ID-backup < $CONTAINER_ID-backup.tarNote the original metadata (eg id of the original image) will be lost. This should be fixed in future versions of docker.
Adding here so one can find from summary that question was answered. Thanks Solomon!
Comments
export has some limitations: it won't export the data volume.
Here's data volume means:
- There's a
VOLUMEdefined in the image's Dockerfile. - 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:
- Visit the data: (in a bash)
docker run -it --volumes-from target_container ubuntu bash
- Backup to host: (a postgres container)
docker run -it --volumes-from some_postgres -v /host/path:/container/path --rm ubuntu bash -c "tar -cvf /container/path/postgres-backup.tar /var/lib/postgresql/data"
Comments
you can also using save and load.. here's the sample
sudo docker imagesawan@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 GBsudo docker save google_star/_version_1.10 > my_docker-backup.tgzrestore it using (
sudo docker load < my_docker-backup.tgz)check your images using
sudo docker imagesin your new docker machine