22

I'm using Docker for Mac Version 1.12.0-beta21 (build: 11019) on OS X 10.11.6. The container folder in $HOME/Library/Containers/com.docker.docker contains 3.1 GB of space. docker images -a however only shows one image which is 330 MB.

How can I clean up the container folder, so that it only contains the images I'm able to use?

Update

There is an open issue regarding this problem: https://github.com/docker/for-mac/issues/371

3 Answers 3

22

try:

docker system prune -a

https://docs.docker.com/engine/reference/commandline/system_prune/

Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.

2
  • 1
    Does not work. Gives Total reclaimed space: 0B Still with du -hs ~/Library/Containers/com.docker.docker I get 16G
    – JaakL
    Oct 28, 2018 at 9:41
  • 1
    This works for me.
    – Tran Triet
    Jun 28, 2020 at 20:55
11

Spotify have a useful docker image called docker-gc which will clean up unused images.

As per the Github page for it, you can run it as a container itself:

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc spotify/docker-gc

I have that aliased to docker-gc which I run periodically to clean things up.

6
  • I'm on OS X and not on linux.
    – ohcibi
    Aug 16, 2016 at 9:23
  • @ohcibi As am I.
    – Burhan Ali
    Aug 16, 2016 at 13:11
  • 1
    Okay I found that: github.com/docker/for-mac/issues/371
    – ohcibi
    Dec 14, 2016 at 16:45
  • 1
    Do you know what's the difference between this garbage collector and docker system prune -a? Jan 28, 2019 at 14:44
  • 1
    @Manu No, I don't. docker system prune didn't exist when I wrote this answer. It was introduced 5 months later. Also I don't use the docker-gc command any more. Looking at the repo though, it looks like the main difference is that you have more control over what gets pruned.
    – Burhan Ali
    Jan 28, 2019 at 15:23
11

Check the size with this command below:

du -h -d 1  ~/Library/Containers/com.docker.docker 

You can easily clean up running:

docker system prune -a

Or restarting the default settings on top bar to clean.

enter image description here

Or create a script like this link to don't lose the images.

https://blog.mrtrustor.net/post/clean-docker-for-mac/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .