Docker stores its containers, volumes, and images in a collection of large files under /var
which is not the greatest thing for backing up incrementally.
With Bareos, I understand that backing up MySQL databases has the same issue and can be done with bpipe.
How can I backup Docker containers (and images, although there's another solution to that*) so that they are easily able to be restored to the same machine or another one?
*(There's also docker registry, which will let you push
images to a remote repository, which works a bit like a backup also, but without the backup mindset. And it only works for images, not containers or volumes.)
For images, one way you can do this is to use the save command offered by Docker. By running:
$ docker save --output output_filename.tar your_image
, Docker will save the image you have specified to a tar file within the directory you are currently in. You are then able to save this image, or move it to another machine.For containers, you can use the export command. This will save the contianer's filesystem to a tar file. This is done by running:
docker export --output="output_filename.tar" your_container
.For using the image, you can use the load command to import the tar file. This can be done by running:
$ docker load --input your_image.tar
.