ClearDisk
Buy for $10Download ClearDiskDownload
A LITTLE MORE CLARITY

How to delete Docker images on Mac

To delete Docker images on Mac, run docker image rm <name:tag> for a single image or docker image prune -a to remove every image not used by a running or stopped container. Docker Desktop then returns the freed blocks inside Docker.raw to macOS within a few seconds.

1. List your images and the containers using them

Docker Desktop must be running: the docker command on your Mac talks to an engine inside Docker Desktop’s Linux virtual machine, and if the app is closed every command fails with an error about connecting to docker.sock. With it running, docker image ls lists each image with its repository, tag, image ID and size. An image with several tags appears once per tag, but its size is stored only once, so don’t add up rows that share an ID.

Recent Docker versions hide untagged images from the default list; add -a to see them too. Then run docker ps -a. Docker won’t normally remove an image that any container is based on, and that includes stopped containers. In Docker Desktop, the Images view marks those images In use and can sort the list into In use, Unused and Dangling.

docker image ls
docker image ls -a
docker ps -a

2. Delete one image by name or ID

docker image rm, or its older alias docker rmi, accepts a name:tag, a short or full image ID, or a digest. Given a name:tag, it removes that tag. If it was the image’s only tag, the image is deleted too, and the output shows an Untagged line followed by Deleted lines. If the image still has other tags, you only see Untagged and no space comes back, because the data still belongs to the remaining names.

Given an ID that has several tags, Docker refuses and asks for -f; with -f it removes every tag and the image. In Docker Desktop, open Images and select the bin icon on the row. Before deleting an image you built yourself and never pushed, make sure you can rebuild it: it can’t be pulled back from a registry.

On Apple silicon, the containerd image store that current Docker Desktop uses can keep more than one platform variant of an image, for example arm64 and an amd64 variant pulled for testing. docker image ls --tree, marked experimental, shows them, and docker image rm --platform linux/amd64 removes one variant. Docker asks for --force there, because that content goes from every image that shares it.

docker image rm myapp:old
docker image rm 4e38e38c8ce0
docker image rm myapp:dev myapp:test

3. Delete images whose name matches a pattern

The reference filter matches image names with shell-style wildcards. A pattern without a tag, such as myapp, matches every tag of that repository; myapp:1.* matches only the 1.x tags. The asterisk doesn’t cross a slash, so use myorg/* for images under a namespace. Always quote the pattern: zsh, the default shell on a Mac, tries to expand an unquoted * itself and stops with “no matches found.”

Preview the match first, then pass the same filter to docker image rm. Printing each match as name:tag, rather than as an ID, untags images cleanly even when one ID carries several names, and avoids the “must be forced” error. The shell substitutes the list before docker image rm runs, so if nothing matches you get a harmless “requires at least 1 argument” message.

docker image ls --filter "reference=myapp"
docker image ls --filter "reference=myapp:1.*"
docker image rm $(docker image ls --filter "reference=myapp" --format "{{.Repository}}:{{.Tag}}")

4. Delete all images

The clean way to delete everything you aren’t using is docker image prune -a. It removes every image without at least one container, running or stopped, and asks for confirmation first. Add --filter "until=720h" to limit it to images created more than 30 days ago. Images with a container are left alone, so a second step is needed if you want those gone as well.

The literal answer, docker image rm $(docker image ls -q), hands every image ID to the remove command. Images that containers use fail with conflict errors, which is Docker protecting them, and IDs with several tags fail unless forced. Resist adding -f to silence that. To empty Docker completely, remove the containers first, knowing that deletes their writable layers. Image commands never touch volumes.

docker image prune -a
docker image prune -a --filter "until=720h"
docker image rm $(docker image ls -q)

Why free space on your Mac may not change right away

Docker Desktop keeps images inside one disk image file. When images are deleted, Docker returns the freed blocks to macOS; Docker’s documentation says this takes a few seconds for Docker.raw and a few minutes for the older Docker.qcow2 format. The file’s listed size can stay large because it is a sparse file, so check available space rather than the file size.

If docker system df still shows a large total, look at build cache and stopped containers, which can hold the same layers. Docker Desktop also keeps separate classic and containerd image stores, and switching between them hides the other store’s images without deleting them. The Docker.raw guide below explains how to confirm what the disk image really occupies.

docker system df

What makes an image dangling

Build myapp:latest, change the Dockerfile and build myapp:latest again. The tag moves to the new image, and the old one is left with no name: it appears as <none>:<none> and, if no container uses it, it is dangling. Pulling an updated version of a tag you already have can leave the previous copy in the same state. Docker’s own definition is an image that isn’t tagged and isn’t referenced by any container.

Don’t confuse dangling images with intermediate images. The legacy builder saved each build step as an untagged parent image, and docker image ls -a shows those as <none> too. They belong to tagged images and aren’t dangling; the dangling filter only lists untagged images at the end of a chain.

What makes an image unused

An unused image is one that no container is based on, running or stopped. The name doesn’t matter: postgres:16, pulled for a project whose containers you already removed, is unused, and so is every dangling image. A stopped container counts as use, so an image whose only container exited months ago is still in use until that container is removed.

Docker Desktop’s Images view uses the same terms. It shows an In use tag next to images used by running or stopped containers, and can sort the list into In use, Unused and Dangling, which is the easiest way to see both groups at once on a Mac.

Remove dangling images with docker image prune

docker image prune, with no flags, removes dangling images only, after a confirmation prompt. It is the low-risk cleanup: these images have no name, and nothing runs from them. The exception is an untagged image you still want, such as a build you never pushed. Give it a name with docker tag before pruning and it stops being dangling. Dangling images are the ones that pile up quietly: each rebuild of a large image can leave the previous copy behind, so a day of Dockerfile changes is a good moment to prune.

docker system prune also removes dangling images, together with stopped containers, unused networks and build cache. If you only meant to clear images, the image command is the narrower tool.

docker image prune
docker tag 8abc22fbb042 myapp:keep

Remove unused images with docker image prune -a

docker image prune -a widens the prune to every image without a container. That includes base images you’ll download again on the next pull or build, and images you built locally, which need their source and build steps to recreate. --filter "until=168h" limits it to images created more than a week ago; label filters are available too.

Docker’s reference notes that the confirmation prompt always warns that all dangling images will be removed, even when you pass a filter, so read the filter rather than the prompt. After pruning, Docker Desktop returns the freed space to macOS through its disk image, which the Docker.raw guide explains.

docker image prune -a
docker image prune -a --filter "until=168h"

If Docker refuses to delete an image: read the error

The message has a fixed shape: conflict: unable to delete, the image ID or name, then either “must be forced” or “cannot be forced,” then the reason. “Must be forced” marks a soft conflict that -f can override; “cannot be forced” marks a hard one that only removing the dependency will clear. The reason names the container or explains the dependency.

The repository-reference variant appears when you remove a name:tag that a container was created from. Depending on your image store it reads “unable to remove repository reference … (must force)” or “unable to delete … (must be forced),” and it ends with the container that is using the image.

  • image is being used by running container: stop and remove that container first. This one can’t be forced.
  • image is being used by stopped container: remove the stopped container, then the image.
  • image is referenced in multiple repositories: the ID has several tags. Remove them by name:tag, or use -f to remove all of them.
  • image has dependent child images: another image was built on top of this one. Delete the child first. This one can’t be forced either.
  • container … is using its referenced image …: a container was created from this name:tag. Remove the container, or keep the image.

Remove the container, then the image

Stop the container if it is running, remove it, then remove the image. With the dependency gone, Docker can delete the image, and the space the container’s layers occupied comes back too. For a Compose project, docker compose down removes the project’s containers first; its --rmi local option also removes images the project built that have no custom tag.

If the container belongs to something you still run, such as a Compose service, think twice: deleting the image only means Docker downloads or builds it again on the next start. When an image has several tags, removing one name:tag only untags it. Remove each name you no longer want; when the last tag goes, the image is deleted. docker image ls shows every tag that shares the ID.

docker stop 4a7f7eebae0f
docker rm 4a7f7eebae0f
docker image rm myapp:latest

Deal with dependent child images

A child image depends on a parent stored locally, which mostly happens with the classic image store and the older, non-BuildKit builder that saved each step as its own image. The containerd image store that current Docker Desktop uses by default doesn’t perform this check, so on an up-to-date Mac you are more likely to meet the other errors.

Images created after the parent are candidates; the since filter lists them. Delete the children you don’t need, or run docker image prune to clear the dangling ones, then remove the parent. If a child is something you still use, keep the parent: it holds layers the child needs.

docker image ls --filter "since=4e38e38c8ce0"
docker image prune

Common questions

Why won't Docker let me delete an image?

Docker won't normally remove an image that any container is based on, including stopped ones, so you need to remove the container first. An image ID with several tags is also refused unless you add -f.

Does removing one tag from a Docker image actually delete it?

Only if that was the image's only tag. If it still has other tags, removing one just untags it, and no space comes back because the data still belongs to the remaining names.

Why does Docker.raw still look large after I delete images on my Mac?

Docker returns freed blocks to macOS quickly, but Docker.raw is a sparse file, so its listed size can stay large; check available space rather than the file's size. Build cache and stopped containers can also hold the same layers even after the images are gone.

What does docker image prune -a actually remove?

It removes every image that no container, running or stopped, is using, after asking for confirmation. Adding a filter like until=720h limits it to images created more than 30 days ago.

What does <none>:<none> mean in my Docker image list?

It means the image has no name or tag, which usually happens when a tag moves to a newer build and leaves the old image behind. If no container uses it, that image counts as dangling.

Is an image used by a stopped container considered unused in Docker?

No. A stopped container still counts as using its image, so that image stays in use until the container itself is removed, even if the container hasn't run in months.

What does "must be forced" mean in a Docker deletion error?

It marks a soft conflict that the -f flag can override. "Cannot be forced" instead marks a hard conflict that only removing the actual dependency, such as a running container, will clear.

References & further reading

These guides combine the linked official guidance with ClearDisk’s documented behavior. Your files and app settings determine the right next step.

Main guide: developer storage on Mac · Related pillar: clear Xcode Derived Data on Mac · Browse all Developer storage guides →

FROM A NUMBER TO AN ANSWER

See what’s using
your space.

Explore your Mac with ClearDisk’s free local scanner.
Review the files. Keep the control.

Download free scannermacOS 15+ · version 2.2.1Cleanup license: $10 once