Skip to content
Log In Sign Up info@muvcloud.com

Remove One Image

docker image ls
docker image rm nginx:1.30

docker rmi nginx:1.30 is the older short form of the same command. Name the image by repository and tag, or by the image ID from the first column of the list. You can give several names in one command.

An image can carry several tags. Removing one tag removes only that name; Docker deletes the layers when the last tag that points to them is gone.

Look Before You Delete

docker system df
docker image ls
docker ps -a

docker system df shows, for each type of object such as images, containers, and local volumes, the total, the number in use, the size, and how much is reclaimable. docker system df -v lists every item. docker ps -a shows which containers exist, running or stopped, and which image each one uses. To see how full the disk is overall, see how to check disk space in Linux.

When Docker Refuses: Image in Use

Docker does not delete an image that a container still uses, even a stopped container. The error says there is a conflict and names the container ID. Find and remove that container first:

docker ps -a --filter ancestor=nginx:1.30
docker rm old_web
docker image rm nginx:1.30

docker image rm -f forces the removal of the name even while a container uses the image. The layers stay on disk as long as any container, running or stopped, still uses them, so -f rarely saves space and leaves an untagged image behind.

Dangling Images

A dangling image has no tag. It is left behind when you build or pull a newer image under the same name. List and remove them:

docker image ls -f dangling=true
docker image prune

docker image prune removes dangling images only and asks for confirmation. Add -f to skip the question in scripts.

Remove All Unused Images

Read this before you run it: the next command deletes every image that no container uses. An image used by a stopped container counts as used and stays. Images you built on the server and never pushed to a registry are gone and must be rebuilt. Anything you start later downloads its image again.

docker image prune -a

To keep recent images, limit it by age:

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

That removes unused images created more than seven days ago.

Remove Every Image

On a test machine you may want all images gone, including those of stopped containers. Remove the stopped containers first, then the images. Anything a stopped container wrote outside a volume is deleted with it, so check the list from docker ps -a first:

docker container prune
docker image rm $(docker image ls -q)

Images that running containers use stay, and Docker prints an error for each of them, as it does for an image ID with several tags. Another way to pass a list of IDs to a command is shown in the xargs guide.

docker system prune and Volumes

CommandWhat it removes
docker container pruneStopped containers
docker image pruneDangling images
docker image prune -aAll unused images
docker builder pruneBuild cache
docker system pruneStopped containers, unused networks, dangling images, build cache

docker system prune -a also removes all unused images. Volumes are a different matter: they hold databases, uploads, and anything else a container writes. Since Docker Engine 23.0, docker system prune --volumes and docker volume prune remove anonymous volumes that no container uses. docker volume prune -a also removes every named volume without a container, and the database volume of a project you stopped with docker compose down is one of them. There is no undo. List the volumes first and back up any you want to keep:

docker volume ls
docker volume ls -f dangling=true
docker system prune --volumes

Keep It from Growing Again

  • Prune on a schedule: a cron entry running docker image prune -f weekly removes dangling images. See how to list cron jobs to check what is already scheduled.
  • Pin tags: fixed tags such as nginx:1.30 make it clear which images are still needed.
  • Clean up after updates: run docker image prune after replacing containers with newer images.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations