Server AdministrationUpdated November 24, 2026·8 min read

How to Remove Docker Images

Deleting one image takes docker rmi <image>, the short form of docker image rm. For bulk clean-up there is docker image prune: by itself it clears dangling images, and with -a it clears every image that no container uses. This Docker remove image guide walks through both, shows a safe way to remove all images, and decodes the errors you get when an image is still in use.

Docker remove image commands at a glance

Task Command
List images docker images
Remove one image docker rmi nginx:1.27
Remove by image ID docker rmi 3f57d9401f8d
Force-remove an image docker rmi -f <image>
Remove dangling images docker image prune
Remove all unused images docker image prune -a
Remove unused images older than 24 hours docker image prune -a --filter "until=24h"
Remove every image docker rmi -f $(docker images -aq)
See how much space images use docker system df

Before you delete Docker images

An image disappears in a second; getting it back onto a busy server can take far longer. So run through three checks beforehand:

  • Is a container built from it? docker ps -a --filter ancestor=<image> answers that, counting stopped containers too.
  • Does anything rely on it? Look for the tag in Compose files, CI pipelines, cron jobs and deploy scripts. They'll fetch or rebuild the image on their next run, and break outright if the registry is out of reach.
  • Is there another copy? Images you built here and never pushed have no backup. Keep one with docker save -o myapp.tar myapp:1.0 before deleting, just in case.

Find the image you want to remove

List the images on the host:

docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        1.27      3f57d9401f8d   2 weeks ago    192MB
nginx        latest    3f57d9401f8d   2 weeks ago    192MB
postgres     17        b781f3a53e61   3 weeks ago    438MB
<none>       <none>    9c7a54a9a43c   5 weeks ago    1.1GB

An image can be named by repository:tag or by its ID. A short prefix of the ID is enough as long as it is unique, so docker rmi 3f5 usually does the job.

The <none> rows are dangling images: layers left without a tag, typically after a rebuild or after pulling a newer version under the same name. Clean those up first; docker images -f dangling=true shows just that group.

Remove a single image with docker rmi

docker rmi postgres:17

docker rmi, docker image rm and docker image remove are one command under three names. Several images can go in a single call:

docker rmi postgres:17 redis:7 9c7a54a9a43c

Tags and images. In the list above, nginx:1.27 and nginx:latest share an image ID. So docker rmi nginx:latest deletes only that tag, and the image itself survives because nginx:1.27 still references it. Docker deletes the image once its last tag is gone, or when you remove it by ID with -f.

docker rmi acts on the local machine alone. Nothing is deleted from Docker Hub or any other registry.

When Docker refuses: "image is being used by a container"

The most common error looks like this:

Error response from daemon: conflict: unable to remove repository reference "postgres:17"
(must force) - container 4c01db0b339c is using its referenced image b781f3a53e61

Docker refuses to delete an image that any container was created from, stopped containers included. Your choices:

  1. Remove the container, then the image. This is the tidy way:

    docker ps -a --filter ancestor=postgres:17   # find containers using the image
    docker rm 4c01db0b339c                        # remove the stopped container
    docker rmi postgres:17
    

    Our guide to stopping and removing Docker containers covers running containers and removing several at once.

  2. Force it with -f. docker rmi -f postgres:17 removes the tag even though a container uses the image. Docker's reference notes you cannot remove the image of a running container without -f. Forcing leaves the container in place, now pointing at an untagged image, which is confusing later. Prefer option 1.

Remove dangling images with docker image prune

docker image prune

That clears every dangling image (the <none> rows), after a confirmation prompt; in scripts, -f skips the prompt. No container ever uses a dangling image, so you can run this whenever you like.

Remove all unused images

docker image prune -a

Adding -a widens the net to every image no container references, where stopped containers count as references. Images you pulled but never ran go as well. You get the most space back this way, at the cost of re-downloading those images on the next docker run or docker compose up.

A filter softens it. To spare anything recent:

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

until takes a duration like 24h or 168h, or a timestamp. Labels work as filters too; --filter "label!=keep" skips any image you have labelled to keep.

Remove all Docker images

To clear out every image on the host, even ones containers are using:

docker rmi -f $(docker images -aq)

docker images -aq lists all image IDs and rmi -f deletes each one. Save this for machines you genuinely want to reset, like a build server or a test VM. To get rid of the containers as well, remove them before the images:

docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -aq)

When a list comes back empty, Docker complains that it needs at least one argument. Nothing was there to remove, so you can ignore it.

Clean up images, containers and build cache together

docker system prune goes further and clears, in one pass:

  • stopped containers
  • unused networks
  • dangling images
  • unused build cache
docker system prune        # dangling images only
docker system prune -a     # also every unused image

Volumes are left alone by default, which keeps databases stored in volumes safe; Docker's documentation says that is deliberate. --volumes brings anonymous volumes into scope, so look at what you are about to delete before adding it.

Compare docker system df before and after to see what each type of object occupies and how much came back. On build machines the build cache is often larger than the images, and docker builder prune clears just that cache.

Where Docker images are stored

The host's disk is where images are kept, never a container. Starting with Docker Engine 29, new installations default to the containerd image store, with image data in /var/lib/containerd. Older installations, plus anything upgraded from one, rely on the overlay2 storage driver in /var/lib/docker. To find out which you have, check the storage driver lines that docker info prints.

Resist cleaning those directories by hand. Docker keeps its own record of every layer, and files vanishing underneath it leave it in a broken state, so let docker rmi and the prune commands do the work. One more thing to know: because the containerd store holds each layer twice, once compressed and once unpacked, identical images use more disk there than on an older install.

Automate the clean-up

Servers that pull fresh images all the time, CI deploy targets for example, collect old ones quickly. A weekly cron job holds disk usage steady:

sudo crontab -e
# Every Sunday at 03:00, remove unused images older than a week
0 3 * * 0 /usr/bin/docker image prune -a -f --filter "until=168h" > /dev/null 2>&1

Because of the until=168h filter, anything from the past seven days stays put, so the image you might roll back to is still on disk.

Frequently asked questions

What is the difference between docker rmi and docker image prune?

docker rmi deletes exactly the images you list. docker image prune deletes by rule: dangling images by default, all unused ones with -a.

Does docker rmi delete the image from Docker Hub?

No. It removes the image from the local host only. A copy in a registry stays until you delete it through that registry.

Why does the disk space not go down after removing an image?

Layers may be shared with other images, and Docker keeps a layer while any image still needs it. Containers, volumes and build cache use space too. docker system df -v shows where it has gone.

Is docker image prune -a safe on a production server?

It deletes every image no container uses, including ones a stopped or not-yet-started service depends on. Running containers are untouched, but the next deploy may need to download images again. Add an until filter to hold on to recent ones.

How do I remove images with a specific name?

Pair docker images with a filter. For example, docker rmi $(docker images -q --filter reference='myapp*') deletes every image whose name starts with myapp.

Is deleting a Docker image the same as removing it?

Yes. Docker's command is docker image rm, shortened to docker rmi, and "delete" and "remove" mean the same thing here. docker image remove works as well.

Related guides

On a small OrbitServers VPS, old images are one of the most common reasons the disk fills up, so set up a prune routine early. If Docker on a server is new to you, begin with installing Docker on Ubuntu and keep the Docker commands cheat sheet to hand. Other disk clean-up is covered in how to check disk usage in Linux.

Was this article helpful?

Written by Julius · Product Manager