Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove local Docker images on macOS

I'm using Docker for Mac and for saving disk space I want to get rid of some unused local images. As far as I know the local files are stored in ~/Library/Containers/com.docker.docker.

But even if I remove all images and containers from docker the folder keeps it's size of some GB and not a single byte is released. The only option is to remove the com.docker.docker folder completely but this makes only sense if you want to remove all the data and not only the unused images. What am I doing wrong?

like image 242
Mountain Avatar asked May 17 '17 04:05

Mountain


2 Answers

sudo docker system prune -af

Just simple put the command given above. It will delete all the image automatically.

like image 114
raman Avatar answered Oct 13 '22 03:10

raman


What is going on here is that your docker for mac application is really running a virtual machine. That virtual machine has its own disk, which is what that qcow2 file is. That disk gets lazily allocated and won't take up all it space all at once. Once the space is used inside the vm, then the disk will grow on the host.

The disk image will grow until it reaches the size of the disk. Just because a file gets deleted inside the vm, that will not cause the disk image on the host to shrink again.

There is a possible solution to shrink your disk image: https://forums.docker.com/t/where-does-docker-keep-images-containers-so-i-can-better-track-my-disk-usage/8370/7

I have seen a few folks use this trick with some success.

like image 32
programmerq Avatar answered Oct 13 '22 04:10

programmerq