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 containersdocker rmi $(docker images -f "dangling=true" -q)
- remove image layers that are not used in any imagesdocker 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.