Skip to main content

Backups and Docker

I’ve spent a lot of time recently playing with Docker.

I’ve been building lots of images and containers, and that starts to take up disk space. Lots of disk space. That’s not much of a problem on a local system – space is cheap – but it becomes a problem with incremental backup programs like Time Machine. Suddenly I noticed backups were taking an order of magnitude longer, and backing up gigabytes at a time. Oops.

Incremental backups of my Docker images aren’t very useful, but they force out older snapshots of important data, and slow down my backups. Wouldn’t it be nice to cut that out?

There are two folders than can swell with Docker images:

I’d recommend excluding both of those from your backups – and perhaps search indexes as well. The exact contents of those folders probably isn’t useful to most users; it’s just a collection of binary files that Docker stitches together into something more meaningful.

If you do need to backup a particular image or container, Docker already has commands for saving images and containers to a file, which can be moved around and backed up as usual. But these files are portable across computers, and take up far less space in backups.

In practice, I rarely use these commands. I usually have the Dockerfiles and/or Docker Hub to restore any images, and containers are supposed to be ephemeral. If I have lots of stuff in a container that I want to keep, I’ve probably done something wrong.