26

Problem:

As I download and run containers, they keep taking up more and more space. I found suggestions for cleaning up unused containers and images and I did so. Guess what? They eat up even more disk space!

What I found so far:

It has to do with .docker\machine\machines\default\disk.vmdk file. It only gets bigger!

Log of disk.vmdk:

                            size (MB)
1. with 2 images                1,376
2. downloading a new image X    ?
3. running X as Y               2,963
4. removing Y                   2,963
5. removing X                   3,106
6. removing all the images      3,126

The only fix I found so far was running docker-machine rm default which removes the VM. The problem is that I have to download all the images again. There should be a better fix. Can someone explain:

  1. What is going on?
  2. How to fix it?
Thoran
  • 7,988
  • 7
  • 38
  • 48
  • Yes, that's correct, virtual disks only get bigger; virtual drivers don't know what part of the virtual disk is in use by the OS file system and what part isn't. It's all just bits. – Mark Ransom Apr 22 '16 at 17:18

5 Answers5

21

There are maintainance commands you can run on the more recent versions of Docker. They will free up space used by stopped containers, dangling images and dangling volumes:

docker container prune -f
docker image prune -f
docker volume prune -f
Arnaud Weil
  • 2,078
  • 17
  • 19
11

On windows 10, this was a major issue, space was not freeing up, even after I ran docker system prune I started noticing this when I found that every week; my SSD was filling up every2 or 3 GB of space.

Try opening Docker Desktop, hitting the Troubleshoot icon at the top right of the UI, and then clicking "Clean / Purge data". This reclaimed the space for me.

Also see:

  1. Windows 10: Docker does not release disk space after deleting all images and containers #244
  2. Hyper V ui issue fix
  3. Clear Hyper-V recognize unused sectors
  4. Linux growing docker size issue fix
Shivam Jha
  • 2,153
  • 1
  • 17
  • 29
  • 2
    my SSD went from 37 to 54gb in free space after running that troubleshooter. Had also run `docker system prune` a couple of days ago. Thanks for the tip. – Tiramonium Dec 09 '21 at 12:55
  • 1
    Thanks. after doing everything with docker prune, only this solution works in the end. Claimed back 24GB from Docker. – blaz Jan 10 '22 at 09:39
4

Maybe the images you are using, use volumes. If they do then deleting the container doesn't do the trick. You must delete the volumes as well. In order to do that you must specify the -v flag when deleting a container

docker rm -v <container name or container id>

Depending on your docker version you will have some more commands available. Check this SO thread for more. You can read more about orphaned volumes in this SO thread

Community
  • 1
  • 1
Alkis Kalogeris
  • 15,894
  • 13
  • 56
  • 106
4

After deleting all the unwanted containers and images using the commands below:

  • Docker container rm
  • Docker image rm
  • Docker container prune
  • Docker image prune
  • Docker volume prune

I couldn't see any disk space released. I found out the disk space was released after I restarted my Docker desktop.

Nick Mehrdad Babaki
  • 9,912
  • 14
  • 44
  • 65
1

If anyone is struggling with this problem on Ubuntu:

In my case pruning and removing using the docker command did not help much.

The issue was docker/overlay2 folder.

febrin@laptop:/var/lib$ sudo du -sh docker/overlay2
361G    docker/overlay2

I had to delete it manually.

Febrin
  • 11
  • 1