Docker filling up storage on macOS Docker filling up storage on macOS docker docker

Docker filling up storage on macOS


WARNING:

By default, volumes are not removed to prevent important data from being deleted if there is currently no container using the volume. Use the --volumes flag when running the command to prune volumes as well:

Docker now has a single command to do that:

docker system prune -a --volumes

See the Docker system prune docs


There are three areas of Docker storage that can mount up, because Docker is cautious - it doesn't automatically remove any of them: exited containers, unused container volumes, unused image layers. In a dev environment with lots of building and running, that can be a lot of disk space.

These three commands clear down anything not being used:

  • docker rm $(docker ps -f status=exited -aq) - remove stopped containers
  • docker rmi $(docker images -f "dangling=true" -q) - remove image layers that are not used in any images
  • docker volume rm $(docker volume ls -qf dangling=true) - remove volumes that are not used by any containers.

These are safe to run, they won't delete image layers that are referenced by images, or data volumes that are used by containers. You can alias them, and/or put them in a CRON job to regularly clean up the local disk.


It is also worth mentioning that file size of docker.qcow2 (or Docker.raw on High Sierra with Apple Filesystem) can seem very large (~64GiB), larger than it actually is, when using the following command:

  • ls -klsh Docker.raw

This can be somehow misleading because it will output the logical size of the file rather than its physical size.

To see the physical size of the file you can use this command:

  • du -h Docker.raw

Source: https://docs.docker.com/docker-for-mac/faqs/#disk-usage