A full disk can stop an inference build before your application code even gets a chance to run. To remove all docker images that are not referenced by containers, run `docker image prune -a`. If you truly want every local image gone, first remove the containers that depend on them, then run the prune command. Both steps affect the Docker daemon selected by your current context, so check where you are connected before deleting anything.
Check the target and reclaimable space
Run `docker context show` to see the active context, then `docker info` to inspect the connected daemon. That matters if you switch between a laptop, a remote server, and a GPU build host: local-looking commands can operate on a remote machine.
Next, run `docker system df -v`. Docker reports image, container, volume, and build-cache usage, along with what it considers reclaimable. Shared image layers make individual image sizes misleading; deleting two tags does not necessarily free the sum of their displayed sizes.
Use `docker image ls -a` to inspect the image list and `docker ps -a` to see running and stopped containers. Stopped containers still reference their images, so an image can remain even when nothing is actively running. If an image exists only on this daemon, make sure you can rebuild it or push it to a registry before deleting it. Removal does not delete a copy already pushed to a registry.
Remove images without deleting containers
The least disruptive cleanup is `docker image prune -a`. Docker asks for confirmation, then removes images that are not used by any existing container. The `-a` flag matters: without it, `docker image prune` removes only dangling images, rather than all unused images.
For an unattended script, `docker image prune -a -f` skips the confirmation prompt. I would avoid the force flag until you have verified the context and understand what will be removed. Unused images may still be useful build inputs; deleting them can make the next deployment slower or require a fresh network download.

This command deliberately leaves images referenced by stopped containers in place. If your goal is simply to recover space without disturbing workloads or their saved container state, that is usually the right boundary. Run `docker system df` afterward to see what changed rather than assuming every byte in the image list was freed.
When you really need to remove all docker images
To clear images that are still referenced, deal with their containers first. Review `docker ps -a` carefully: deleting a container also deletes changes stored in its writable layer. Copy anything important out or confirm it is stored elsewhere before proceeding. Data in a separately managed volume is not removed by `docker rm` alone.
Stop specific running containers with `docker stop CONTAINER`, then remove them with `docker rm CONTAINER`. Repeat for each container whose image you intend to delete. Once no containers reference those images, run `docker image prune -a` again.
On a disposable development machine where you have verified that every container can go, `docker rm -f $(docker ps -aq)` stops and removes all containers returned by the active daemon. Then `docker image prune -a -f` removes the now-unused images. The container command is for a Unix-like shell; if there are no containers, `docker rm` receives no IDs and reports an error. Do not run this sequence on a shared host unless you intend to remove everyone’s containers, too.
You may also see `docker rmi -f $(docker images -aq)` suggested as a one-liner. It is less clear about container dependencies and can still encounter conflicts. Removing the relevant containers explicitly, then pruning unused images, makes the scope and consequences easier to inspect.
Handle conflicts and images that remain
If Docker reports that an image is being used by a container, run `docker ps -a` and identify the container before changing anything. A stopped container is still a dependency. Remove that container only after checking whether its writable-layer data matters; otherwise, leave the image in place.
Multiple tags can point to the same image. Removing a tag may simply untag it rather than free the underlying layers. Other images can share those layers too, which is why the reclaimed-space total may be smaller than expected. Rerun `docker image ls -a` and `docker system df -v` to inspect what remains.

Also confirm that you are looking at the same daemon before and after cleanup. Switching Docker contexts or environments can make it appear that images came back when you are actually inspecting a different image store.
Images are not the whole disk bill
Build cache is separate from the ordinary image cleanup described above. If image pruning leaves the disk full, inspect the build-cache entry in `docker system df -v`. `docker builder prune` removes dangling build cache; `docker builder prune -a` targets unused build cache more broadly. Expect future builds to take longer when they cannot reuse those cached steps.
Volumes are another separate category and may contain databases, checkpoints, or other persistent application data. Do not add volume cleanup to an image-removal script just because you need space. Identify the volume and verify its contents and backup status first. Similarly, `docker system prune` has a broader scope than image pruning: it can remove stopped containers, unused networks, and build cache as well as images, depending on its flags. Its volume option adds another significant data-loss risk.
Verify the result before restarting work
Run `docker image ls -a` again. An empty list means there are no images visible in the selected daemon’s image store; it does not mean registry copies, volumes, or all build cache have been removed. Check `docker system df -v` and the host’s filesystem usage to see whether the cleanup addressed the actual disk pressure.
Finally, rebuild or pull the images needed by your next job and confirm that its configuration still points to the intended tags and registry. On an inference host, allow for model and image downloads before bringing traffic back. No panic, just logs: if space is still disappearing, inspect container logs and application data rather than repeating image deletion blindly.
No letters yet — be the first to write.