Introducing ZYNOO General Purpose & CPU Optimized Servers   Learn More >

How to Remove Docker Images: Single, Multiple & Unused

To remove a Docker image, use docker image rm followed by the image name or ID. You can also use docker rmi, which is a shorter version of the same command.

Over time, Docker images can accumulate and consume significant disk space. Removing unnecessary images helps keep your development environment or server organized.

This guide covers the essential Docker remove image commands, including deleting individual images, multiple images, and unused images.

Key Takeaways

  • Use docker image rm or docker rmi to delete specific Docker images.
  • Remove multiple images by specifying several image names or IDs.
  • Use docker image prune to remove dangling images and docker image prune -a to remove unused images.
  • Check container dependencies before removing images to avoid disrupting applications.

1. List Docker Images Before Removing Them

Before deleting images, check what’s stored on your system.

Make sure Docker Engine is installed and running, and that your account has permission to execute Docker commands.

Run:

docker image ls

This displays the available images, including their repository names, tags, image IDs, and sizes.

If you’re new to Docker, our introduction to Docker and containers explains how images work and how they’re used to create containers.

2. Remove a Single Docker Image

To delete a specific image, run:

docker image rm nginx:alpine

This removes the locally stored nginx:alpine image, provided no container dependency prevents its removal.

You can also use the shorter command:

docker rmi nginx:alpine

Alternatively, remove an image using its ID:

docker rmi IMAGE_ID

Replace IMAGE_ID with the actual value shown by docker image ls.

Note: If an image has multiple tags, removing one tag may only untag the image rather than delete its underlying data.

3. Remove Multiple Docker Images

You don’t need to delete images individually.

To remove several images at once, specify their names or IDs in a single command.

For example:

docker image rm nginx:alpine redis:7

Docker attempts to remove both images.

You can also use multiple image IDs:

docker rmi IMAGE_ID_1 IMAGE_ID_2

Replace the placeholders with the IDs you want to remove.

Always verify the selected images before executing bulk removal commands.

4. Remove Dangling Docker Images

Dangling images are untagged images that aren’t referenced by any container. They commonly appear after rebuilding or updating Docker images.

To list them, run:

docker image ls -f "dangling=true"

To remove dangling images:

docker image prune

Docker requests confirmation before proceeding.

This is a useful cleanup option because it targets dangling images rather than every locally stored image.

5. Remove All Unused Docker Images

If you want to free additional disk space, use:

docker image prune -a

The -a option removes all images not referenced by any container, including unused images that still have repository names and tags.

Important: This command can remove images you intend to reuse later. You may need to download or rebuild those images again.

Review your stored images and container dependencies before running it, particularly on production servers.

6. Fix “Image Is Being Used by Container” Errors

Docker may prevent image removal when the image is associated with an existing container.

Check which containers use an image:

docker ps -a --filter "ancestor=nginx:alpine"

This displays matching containers, including stopped ones.

If a container is no longer needed, you can stop and remove it:

docker stop CONTAINER_NAME
docker rm CONTAINER_NAME

Replace CONTAINER_NAME with the actual container name or ID.

Warning: Removing a container deletes its writable layer. Preserve any important data before doing so.

After removing the container, retry the image removal command.

Avoid using docker rmi -f unless you understand the consequences of forced image removal.

7. Verify Docker Disk Space After Cleanup

After deleting unnecessary images, check Docker’s storage usage:

docker system df

This shows disk usage associated with images, containers, local volumes, and build cache.

You can also confirm which images remain:

docker image ls

These commands help verify that your cleanup removed the intended images.

Remember that removing local Docker images doesn’t delete copies stored in remote registries or on other servers. For more information about managing containerized workloads across infrastructure, read our Docker and Kubernetes comparison.

Final Thoughts

Removing unnecessary Docker images is an effective way to reclaim disk space and maintain a cleaner hosting environment.

Use docker image rm for individual images, specify multiple names for bulk removal, or use docker image prune for unused image cleanup.

Before deleting images on a production server, always check whether existing or planned containers still depend on them.

Table of Content

Kubernetes architecture Diagram consists of a control plane and worker nodes that work together to

Choosing dedicated servers in Europe isn’t just about finding the lowest monthly price. Server location,

An unmetered dedicated server gives you exclusive physical hardware with network traffic that isn’t billed

Build your next project with ZYNOO

From your first website to demanding applications, choose the resources and control you need.

Shared Hosting

Start your blog or business website with cPanel, LiteSpeed and CloudLinux.

VPS Hosting

Grow your websites and applications with NVMe storage, KVM virtualization and full root access.

Dedicated Servers

Power demanding projects with your own physical server, dedicated resources and control over your environment.

Scroll to Top