Running out of space because of docker containers / images?

Almost 3 years ago I published a much-needed post around cleaning up space taken by docker (it’s been one of the most popular posts on this blog according to Google Analytics), but since a year or so there’s a much better way to achieve the same.

Disk space has been one of the biggest painpoints for whoever worked with docker: you build containers, run them and don’t bother cleaning them up :) Images, build caches and container filesystems pile up and, before you know it, there’s some 50GB of space taken by docker.

Luckily enough, the docker CLI now has a very simple way to free space taken by images / containers:

1
2
3
4
5
6
7
8
9
10
11
$ docker system prune

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N]

...
Total reclaimed space: 513.6MB

The disadvantage of this approach is that it actually kills a few things you might be interested in (build caches, for example), but it’s one of those instructions each and everyone of us should dump in the crontab of our servers, or run seldom on a local machine.

Adios!


In the mood for some more reading?

...or check the archives.