Cleanup disk space occupied by Docker images

34,631

Solution 1

First try to run:

docker system prune

It will remove:

  • all stopped containers
  • all volumes not used by at least one container
  • all networks not used by at least one container
  • all dangling images

If that's not enough, do:

docker system prune -a

It will remove:

  • all stopped containers
  • all volumes not used by at least one container
  • all networks not used by at least one container
  • all images without at least one container associated to

If you haven't got what you expected, try the following

docker volume prune

It will remove all local volumes not used by at least one container.

Solution 2

Update Q4 2016: as I mention in "How to remove old and unused Docker images", use:

docker image prune -a

(more precise than docker system prune)

It will remove dangling and unused images. Warning: 'unused' means "images not referenced by any container": be careful before using -a.

Then check if the disk space for images has shrunk accordingly.


Original answer:

See the Medium article "How to clean up Docker (~5GB junk!)" from katopz.

It refers to the docker-cleanup script, for removing old exited process, and dangling images.
I have my own aliases as well.

But it also mentions that, since docker 1.10, you now have named volumes that need to be removed as well:

docker volume rm $(docker volume ls -qf dangling=true)

Solution 3

To clean the system memory there are three steps:

  1. Delete docker image
  2. docker system prune -a
  3. quit the docker container app

This worked for me. Around 30gb of space was cleaned after doing the above mentioned steps.

Share:
34,631
vintrojan
Author by

vintrojan

Updated on July 14, 2022

Comments

  • vintrojan
    vintrojan almost 2 years

    I am running docker on windows 10.

    I had a couple of images stored in my machine. The total size of these images accumulated to around ~10GB. I have deleted these images via 'docker rmi -f' command.

    But the space occupied by these images has not been released. If I run 'docker images' command, the deleted images are not listed in the output of 'docker images' command(but the disk space is not cleaned up).

    How can I improve (ie. reduce) the disk space used by docker?

  • ilyas Jumadurdyew
    ilyas Jumadurdyew about 4 years
    It's not working. Even if I don't have any images, containers or volumes at all, it still shows 64GB. System prune -a just shows "Total reclaimed space: 0 B". However ~/Containers/com.docker.docker/Data/com.docker.driver.amd64-‌​linux/Docker.qcow2 is still 64GB. How?!
  • Artur Barseghyan
    Artur Barseghyan about 4 years
    Do you perhaps have any containers running?
  • ilyas Jumadurdyew
    ilyas Jumadurdyew about 4 years
    No only portainer and DB container (Db staus open, because after system prune I lose my custom network). I do really want to use containerization instead of virtualization. However uncontrollable oversizing is too big risk.
  • Artur Barseghyan
    Artur Barseghyan about 4 years
    For how long have you been using Docker? Did you try docker volume prune?
  • ilyas Jumadurdyew
    ilyas Jumadurdyew about 4 years
    Yes, I've tried all kinds of prune. The only solution is to Reset Docker. But is is not good since I loose all my settings, images, networks etc (Even working)
  • Kristaps J.
    Kristaps J. about 4 years
    @ilyasJumadurdyew Try restarting docker. I also had issue that docker disk image didn't actually decrease in size even after prunes. So I just tried to restart docker itself, and it worked, all disk image is clear. (using windows)
  • Macindows
    Macindows over 3 years
    i cleared over 35 GB of junk! tnx, especially for the 2nd command.. dint see it elsewhere..
  • VonC
    VonC over 3 years
    @Macindows Well done. since 2016, there is also docker volume prune that I mention in stackoverflow.com/a/32723127/6309, which could do the same.
  • Surya Tej
    Surya Tej over 3 years
    even after docker restart, the memory occupeid is not cleared. I see several giga bytes of information being stored in C:\ProgramData\docker\windowsfilter folder
  • jay
    jay about 3 years
    any solution yet? i am experiencing the same issues. images deleted but not the Hard disk space
  • Artur Barseghyan
    Artur Barseghyan about 3 years
    Did you try docker volume prune?
  • Dean
    Dean almost 3 years
    Definitely the quit docker and restart is needed to reclaim the space, at least on my Win10 box.