CLEANING UP AFTER DOCKER

Cleaning Up After Docker

Date Published:
Last Modified:

Overview

Docker can end up eating a large amount of hard drive space. Here are some ways of cleaning up after Docker…

System Prune

Docker provides a command to remove dangling images, stopped containers, networks that are not used by any containers, and build cache:

$ docker system prune

For an even more agressive prune, you can add the all and force flags (which it easy to remember due to a rude nmemonic with the acronym af):

$ docker system prune -af

When -af is provided, all unused images will be removed (not just dangling ones), and there will be no confirmation prompt.

When All Else Fails

Sometimes, the above methods just won't clean up enough space. Docker stores some of the build data in the directory /var/lib/docker. This includes container rootfs layers if docker is using the AUFS storage driver (which is the default driver). This directory can get quite large quite quickly, I have seen 50-100GB directories after 6 months of regular docker usage on the machine.

Looks like Docker, Inc. have some contracts with computer data storage manufacturers.

Below is a brute force method to wipe out this directory, which will delete all containers, images and volumes. This will not ruin your Docker installation as Docker does not store any critical executables or configuration in this directory.

$ sudo service docker start
$ sudo rm -rf /var/lib/docker/
$ sudo service docker stop

Like this page? Upvote with shurikens!

Tags:

comments powered by Disqus