Thursday, July 7, 2016

Cleaning up docker device mapper

Docker device mapper is an alternative storage backend to aufs.
During everyday operation lots of images are downloaded that are never  deleted , so the device mapper may end up taking a lot of space in your system, unless you remember to clean it up regularly.

You can see the details about your docker instance by executing

sudo  docker info

This command will tell you what backend you are using and how much space is allocated to it.

After executing a container, you may want to clean up the images it downloaded in order for it to run. People usually forget to do this and eventually they end up taking a lot of space.

An easy way to clean any unused images and cleanup your device mapper is by executing the following command:

sudo docker images -a|awk '{print $3}'|xargs sudo docker rmi

In the past there was a bug that prevented docker from releasing the disk space. This has been now resolved and you should have no issues if you are running a newer kernel than 3.13

3 comments:

  1. My favorite for cleaning older containers: docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm

    ReplyDelete
  2. Yeah that's the other half of the equation. I think it is easier to ignore the images since you do not interact directly with them though.

    ReplyDelete
  3. Yeah that's the other half of the equation. I think it is easier to ignore the images since you do not interact directly with them though.

    ReplyDelete

Note: Only a member of this blog may post a comment.