60

I've just noticed that I ran out of disk space on my laptop. Quite a lot is used by Docker as found by mate-disk-usage-analyzer:

Enter image description here

The docker/aufs/diff folder contains 152 folders ending in -removing.

I already ran the following commands to clean up

Kill all running containers:
# docker kill $(docker ps -q)

Delete all stopped containers
# docker rm $(docker ps -a -q)

Delete all images
# docker rmi $(docker images -q)

Remove unused data
# docker system prune

And some more
# docker system prune -af

But the screenshot was taken after I executed those commands.

What is docker/aufs/diff, why does it consume that much space and how do I clean it up?

I have Docker version 17.06.1-ce, build 874a737. It happened after a cleanup, so this is definitely still a problem.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • 1
    It's not a volume problem - dangling volumes can be removed with `docker volume rm $(docker volume ls -f dangling=true -q)` – Martin Thoma Aug 21 '17 at 13:16
  • Possible duplicate of [How to Force Docker to release storage space after manual delete of file in volumes and containers?](https://stackoverflow.com/questions/44288901/how-to-force-docker-to-release-storage-space-after-manual-delete-of-file-in-volu) – k0pernikus Aug 21 '17 at 13:44
  • 1
    @k0pernikus This is not a duplicate. I already stopped the containers, deleted the images and containers, deleted all volumes and ran system prune. The other question did not do so. – Martin Thoma Aug 21 '17 at 13:51

6 Answers6

48

The following is a radical solution. IT DELETES ALL YOUR DOCKER STUFF. INCLUDING VOLUMES.

$ sudo su
# service docker stop
# cd /var/lib/docker
# rm -rf *
# service docker start

See https://github.com/moby/moby/issues/22207#issuecomment-295754078 for details

It might not be /var/lib/docker

The docker location might be different in your case. You can use a disk usage analyzer (such as mate-disk-usage-analyzer) to find the folders which need most space.

See Where are Docker images stored on the host machine?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • 4
    This is a bruteforce solution that will delete all containers, images and volumes. The OP might want to keep images and volumes that are currently in use. – k0pernikus Aug 21 '17 at 13:45
  • 3
    @k0pernikus I am the OP. I already removed all images and volumes. As I wrote in the question. – Martin Thoma Aug 21 '17 at 13:53
  • :D You got me there. Case in point: it's a solution to the problem, yet if someone else tries this solution just for the diff folder issue, they might not get what they expect. – k0pernikus Aug 21 '17 at 13:55
  • 1
    For me (docker version `1.12`), this is the only working solution, even though I previously removed all images & volumes, and `/var/lib/docker` contains only a `*.db` file, the spaces taken by docker wont' be reclaimed. – ibic Aug 22 '17 at 07:20
  • If you are on AKS or any other cloud you may want to take a disk snapshot before doing anything at all, so that you can easily recover afterwards. In particular in Azure you may temporary move stuff to the `/mnt` or other virtual temp space, restart and see, then possibly move back; but beware, that is an unpersisted and volatile drive! – reim Jan 09 '19 at 10:08
10

This dir is where container rootfs layers are stored when using the AUFS storage driver (default if the AUFS kernel modules are loaded).

If you have a bunch of *-removing dirs, this is caused by a failed removal attempt. This can happen for various reasons, the most common is that an unmount failed due to device or resource busy.

Before Docker 17.06, if you used docker rm -f to remove a container all container metadata would be removed even if there was some error somewhere in the cleanup of the container (e.g., failing to remove the rootfs layer). In 17.06 it will no longer remove the container metadata and instead flag the container with a Dead status so you can attempt to remove it again.

You can safely remove these directories, but I would stop docker first, then remove, then start docker back up.

cpuguy83
  • 5,794
  • 4
  • 18
  • 24
  • 2
    Also note that there is an apparent regression in 17.06.1 that may be causing your issue. This is fixed in the upcoming 17.06.2. – cpuguy83 Sep 02 '17 at 13:34
  • 2
    Could you please add a list of commands one should use today to clean up docker? – Martin Thoma Sep 09 '17 at 11:01
  • 1
    Nothing will auto-clean these removing dirs, however `docker system prune` is the best way to cleanup unused stuff in one command. – cpuguy83 Nov 10 '17 at 16:17
  • 1
    I think `docker system prune` should have the maximum likes here. – Darshan Jul 29 '20 at 10:18
9

docker takes lot of gig into three main areas :

  1. Check for downloaded and compiled images. clean unused and dead images by running below command
    docker image prune -a 
  1. Docker creates lot of volume, some of the volumes are from dead container that are no more used clean the volume and reclaim the space using
    docker system prune -af && \
    docker image prune -af && \
    docker system prune -af --volumes && \
    docker system df
  1. Docker container logs are also very notorious in generating GBs of log overlay2 storage for layers of container is also another source of GBs eaten up . One better way is to calculate the size of docker image and then restrict the docker container with below instructions for storage and logs upper cap. For these feature use docker V19 and above.
    docker run -it --storage-opt size=2G --log-opt mode=non-blocking --log-opt max-buffer-size=4m fedora /bin/bash
Simson
  • 3,373
  • 2
  • 24
  • 38
vinit sharma
  • 453
  • 2
  • 7
  • 12
1

Note that this is actually a know, yet still pending, issue: https://github.com/moby/moby/issues/37724 If you have the same issue, I recommend to "Thumbs Up" the issue on GitHub so that it gets addressed soon.

Robert
  • 1,357
  • 15
  • 26
0

I had same issue. In my case solution was:

  1. view all images:
    docker images

  2. remove old unused images:
    docker rmi IMAGE_ID

  3. possibly you will need to prune stopped containers:
    docker container prune

p.s. docker --help is good solution :)

Dmitry
  • 133
  • 1
  • 7
0

In Macbook MacOS running docker Desktop, you could do the following to purge all docker images, containers, caching and artifacts to claim your space back

# remove all build cache \
docker builder prune -a && \
# remove all stopped containers, unused networks, dangling images & build cache \
docker system prune && \
# remove unused images, all build cache \
docker system prune -a
Hui Zheng
  • 2,394
  • 1
  • 14
  • 18