Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Remove one stopped container with docker rm <container>. To remove a running container cleanly, stop it first with docker stop <container>, then remove it. Use docker container prune to remove all stopped containers, or Docker Compose’s removal command for service containers. These commands have different effects on running processes and stored data, so choose by scope and check whether the container uses volumes before removing it.

Remove one stopped Docker container

Run docker rm followed by the container’s name or ID:

docker rm my-container

The command removes the specified container; Docker also accepts multiple names or IDs in one command. The equivalent long form is docker container rm. Docker documents the command as one that removes one or more containers: Docker container rm reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Stop a running container before removing it

For an orderly shutdown, stop the container and then remove it:

docker stop my-container
docker rm my-container

Docker sends the container’s configured stop signal—SIGTERM by default—and then sends SIGKILL if its main process has not exited by the end of the grace period. When no timeout is configured, the documented default is 10 seconds for Linux containers and 30 seconds for Windows containers; configuration and platform affect the behavior. See the Docker container stop reference.

Force-remove a running container

If you need immediate removal rather than a graceful stop, use:

docker rm -f my-container

Force removal sends SIGKILL to the container’s main process. Because this does not allow the process to shut down gracefully, use it only when that interruption is acceptable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Remove all stopped containers

To remove every stopped container, run:

docker container prune

Docker asks for confirmation by default. To skip the prompt, add --force:

docker container prune --force

Use a filter when you want to limit which stopped containers qualify. For example, this command targets stopped containers older than 24 hours:

docker container prune --filter "until=24h"

Prune supports filters including until and labels. Check the filter carefully before confirming; the command removes every stopped container that matches it. See the Docker container prune reference.

Remove containers managed by Docker Compose

From the Compose project directory, remove stopped service containers with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker compose rm

To stop service containers as part of removal, add -s. To also remove associated anonymous volumes, add -v:

docker compose rm -s -v

Compose removal preserves anonymous volumes unless -v is supplied. Data stored only in the container’s writable filesystem is lost when the container is removed. Named volumes are distinct from anonymous volumes; inspect the project’s volume configuration and the Docker Compose rm reference before deleting data you need.

Understand what happens to container data and volumes

Removing a container is not the same as deleting every volume associated with it. With the ordinary docker rm command, associated volumes are not removed. Add -v to remove anonymous volumes associated with the container:

docker rm -v my-container

This does not remove named volumes. Docker also cannot remove a volume that is still in use. Data that exists only in the container’s writable filesystem disappears when the container is removed, so preserve it in a volume or copy it elsewhere if it must survive.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a one-off container you want Docker to clean up automatically on exit, start it with --rm:

Best Value
Docker Container Linux Devops Programming Coding T-Shirt
  • Docker, Docker Swarm, Docker Compose, Programmer, Developer, Coding, Programming, Software Engineer, Code, DevOps, Deploy, Deployment, Kubernetes, Salt, Puppet, Chef, Terraform, Container, AWS, Azure, Cloud, Geek, Funny, Computer, Software, Tech, IT
  • Integration, Scrum, Compile, Compilation, Science, Bug, Debug, Python, Linux, Java, Javascript, Scala, Dotnet, Kotlin
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem
docker run --rm ...

This automatically removes the container and its associated anonymous volumes after it exits; named volumes are retained. See the Docker container run reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the right cleanup command

Command Scope Process handling Data considerations
docker rm <container> One or more specified containers Use for stopped containers; stop a running container first for graceful shutdown. Does not remove associated volumes by default.
docker stop <container>, then docker rm <container> One specified running container Requests shutdown, then sends SIGKILL if the process exceeds the grace period. Removing the container loses data stored only in its writable filesystem.
docker rm -f <container> One specified running container Force-removes it using SIGKILL. Does not remove associated volumes by default.
docker container prune All stopped containers, optionally limited by filters Does not target running containers. Removes containers, not their associated volumes by default.
docker compose rm Stopped containers for Compose services Add -s to stop them if needed. Add -v to remove associated anonymous volumes; container-filesystem data is lost.

Do not use system prune for container-only cleanup

docker system prune has a wider scope than container removal: it can remove unused containers, networks, images, and build cache. Volumes are excluded by default; adding --volumes includes anonymous-volume pruning. Use it only when you intend to clean up those other unused resources as well. See the Docker system prune reference.