How to Reduce Docker Disk Usage

Updated · MintDisk team

MintDisk Developer Pack showing unused Docker images and stopped containers

Docker on a Mac keeps everything, images, containers, volumes and build cache, inside one large disk image file managed by Docker Desktop. It grows with every image you pull and every build you run, and it rarely shrinks by itself. This guide shows how to reduce Docker disk usage with Docker's own commands, from the safest to the most thorough.

Every prune command below deletes data permanently. Read what each one removes before you run it, and never prune volumes you have not backed up.

The commands work the same in Docker Desktop and other Docker setups on macOS. The last section covers what is specific to Docker Desktop: the disk image file and its size limit.

Measure what Docker is using

Start Docker Desktop, then ask Docker how much space it uses. This command only reads.

docker system df
Terminal running docker system df, a table of images, containers, local volumes and build cache with their size and reclaimable space
docker system df shows how much each kind of Docker data uses and how much is reclaimable. Example output with demo files.

The output has one row per type of data with the columns TYPE, TOTAL, ACTIVE, SIZE and RECLAIMABLE. The RECLAIMABLE column is the space Docker could free because nothing currently uses it.

docker system df -v

The verbose form lists each image, container and volume. For images it shows SHARED SIZE, the layers an image has in common with others, and UNIQUE SIZE, the space that only that image uses. Deleting an image frees its unique size, not its full size.

What each kind of Docker data is

TypeWhat it isSafe to prune?
ImagesRead-only templates you pulled or builtDangling ones always; unused tagged ones if you can pull them again
ContainersRunning or stopped instances of an image, with their writable layerStopped ones, once nothing inside is needed
VolumesPersistent data, such as database filesOnly after you check and back up the contents
Build cacheLayers saved to speed up docker buildYes; builds get slower until the cache is rebuilt
NetworksVirtual networks for containers; they use almost no diskUnused ones, with docker network prune

Remove stopped containers

Stopped containers keep their writable layer, and with it any data written inside the container, until they are removed.

docker container prune

This removes all stopped containers. Docker asks for confirmation; add --filter "until=24h" to keep containers stopped in the last day.

Data written inside a container, rather than in a volume, is lost when the container is removed. Copy out anything you need first with docker cp.

Remove unused images

docker image prune

By default this removes only dangling images: untagged layers left behind when you rebuild an image with the same tag. They are safe to remove.

docker image prune -a

With -a, Docker removes every image that no container uses, tagged or not.

docker image prune -a also deletes base images you will need again. The next docker run or build downloads them, which takes time and bandwidth. Use it when you really need the space.

Clean up the build cache

If you build images often, the build cache can be the largest item in docker system df.

docker builder prune
Terminal running docker builder prune, which asks for confirmation before it removes the dangling build cache
docker builder prune asks before it deletes anything; answer y only when you are sure.

Without options it removes dangling build cache. Add --all to remove all unused build cache, or keep part of it with --keep-storage, for example docker builder prune --keep-storage 10GB. Add --filter "until=72h" to remove only cache older than three days.

Current Docker Desktop versions build with Buildx, whose own prune command uses newer names for the size limits: --reserved-space (space always kept for cache), --max-used-space (the most the cache may use) and --min-free-space (free disk space to aim for). For example:

docker buildx prune --reserved-space 10GB

On docker buildx prune, --all has a different meaning than on docker builder prune: it includes internal and frontend images. Check docker buildx prune --help on your version before you combine flags.

After a full build-cache prune, the next build of every project starts from scratch and takes longer.

Volumes: be careful

Volumes hold the data your containers keep, such as databases. Docker never removes them unless you ask.

docker volume ls
docker volume prune

Since Docker Engine 23, docker volume prune removes only anonymous volumes that no container uses. To remove unused named volumes as well, you need docker volume prune --all.

A pruned volume and the data in it cannot be recovered. Check docker volume ls and back up any database or file you need before you remove a volume.

Everything at once: docker system prune

docker system prune

By default this removes all stopped containers, all networks not used by a container, all dangling images and unused build cache. Volumes are kept, to prevent important data from being deleted. Add -a to remove all unused images as well, and --volumes to remove anonymous volumes.

Because it combines several prunes, docker system prune is convenient but less precise. Running the individual commands above lets you see and control each step.

A safe routine

Run the commands in this order, from the least to the most disruptive, and check docker system df between steps to see what each one freed:

  1. docker container prune to remove stopped containers.
  2. docker image prune to remove dangling images.
  3. docker builder prune to remove dangling build cache.
  4. Only if you still need space: docker image prune -a and docker builder prune --all.
  5. Volumes last, one at a time, after checking what they contain.

Keep Docker small from now on

  • Start throwaway containers with docker run --rm: Docker removes the container as soon as it exits, so it never piles up.
  • Set a Disk usage limit in Docker Desktop that leaves enough room for the rest of your work.
  • Keep the build cache at a size you are happy to spend: docker builder prune --keep-storage 10GB, or with Buildx docker buildx prune --reserved-space 10GB, so builds stay fast without the cache growing forever.
  • Check docker system df once in a while; the RECLAIMABLE column tells you whether pruning is worth it.

Manage Docker Desktop's disk on Mac

On a Mac, Docker's data lives in a disk image file. Docker's documentation gives the example path ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw; the actual location is shown in Docker Desktop under Settings > Resources > Advanced.

  • Disk usage limit (Settings > Resources > Advanced) sets the maximum space Docker can use. Older versions call this setting Disk image size.
  • Space is freed when you delete images; files deleted inside running containers are not freed automatically.
  • Some tools, including Finder, may report the file's maximum size rather than the space it really uses.

Don't move or delete Docker.raw in Finder. Lowering the disk limit, or using Clean up data in the Troubleshoot menu, deletes the disk image, and with it every container and image on this Mac.

Questions and answers

Why is Docker still large after I pruned everything?

Docker's documentation notes that space is only freed when images are deleted, and that files deleted inside running containers are not freed automatically. For that case the Docker Desktop FAQ gives a command, docker run --privileged --pid=host docker/desktop-reclaim-space, that reclaims the space; it can take a few minutes.

Is docker system prune safe?

It never removes volumes or running containers without extra flags, so your persistent data is safe. It does remove stopped containers and their data, unused networks and build cache, so read the list it prints before you confirm.

How do I see what a volume holds before removing it?

docker volume inspect <name> shows where it is mounted and which labels it has. Containers that use it are listed by docker ps -a --filter volume=<name>.

Where are Docker images stored on a Mac?

Inside Docker Desktop's disk image file, not as separate files you can browse in Finder. Use the Docker CLI or Docker Desktop's Images view to see and remove them.

See Docker's leftovers next to your other developer data

MintDisk's Developer Pack lists dangling images and stopped containers with their size and removes them with Docker's own prune commands; Deep cleanup can also clear Docker's unused build cache. Volumes and tagged images are never touched. Removal is permanent, as with the commands above, and Docker must be running.

MintDisk Developer Pack listing local AI models, unused Docker images, stopped containers and unavailable Xcode simulators
MintDisk's Developer Pack: Docker leftovers and unavailable Xcode simulators, each with its size.

Related

Sources

First published . Commands and menu paths were checked against the sources above on the update date.

Ask AI assistants about MintDisk

Independent, real-time insights from major language models.