Interview Q&A / Docker & Kubernetes

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is the difference between docker rm, docker rmi and docker system prune?

SHORT ANSWER

docker rm deletes containers, docker rmi deletes images, and docker system prune bulk-removes stopped containers, unused networks and dangling images. Add -a for all unused images, and --volumes for unused volumes.

Explain it simply

Think of a hostel. Containers are guests staying in rooms; images are the room blueprints. docker rm evicts a guest. docker rmi shreds a blueprint. docker system prune is the weekend cleaning crew that clears all empty rooms and stray papers.

docker rm web removes a stopped container (use -f for a running one). docker rmi nginx removes an image, but fails if any container, even a stopped one, still uses it. docker system prune removes stopped containers, networks no container uses, dangling images (untagged layers left behind by rebuilds) and build cache. By default it keeps volumes, because they may hold data. -a also removes every image not used by a container, and --volumes also removes unused volumes, which is destructive.

On a student laptop, Docker can quietly eat tens of GB, so this is a regular chore.

Example

bash
docker rm web                 # remove a stopped container
docker rm -f web              # force-remove a running one
docker rmi nginx:1.27         # remove an image
docker image prune            # only dangling images
docker system prune           # containers, networks, dangling images, cache
docker system prune -a --volumes   # aggressive: check first

What to say in the interview

"rm removes containers, rmi removes images, and system prune cleans up unused containers, networks, dangling images and build cache. Volumes are skipped unless I pass --volumes, so I take care with that flag because it deletes data."

Common mistakes

  • Running prune --volumes on a machine where a database lives in a named volume.

#docker#commands#cleanup

Related questions

Practise more Docker & Kubernetes questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Docker & Kubernetes quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.