docker rm Command Reference
Remove one or more containers.
docker rm deletes stopped containers. With -f it stops and removes a running container in one step. In CI it cleans up leftover containers between jobs on a persistent runner; prefer docker run --rm so containers self-clean.
Common flags
-f, --force- force-remove a running container (SIGKILL then remove)-v, --volumes- also remove anonymous volumes attached to the container-l, --link- remove the specified link rather than the container
Example
shell
docker rm -f app-web app-db
docker rm -f $(docker ps -aq) 2>/dev/null || trueIn CI
On persistent runners, force-remove leftover containers at the start of a job so a stale name does not conflict with a new one ("Conflict. The container name is already in use"). Add || true so an empty list does not fail the step. -v also frees anonymous volumes.
Key takeaways
- -f stops and removes a running container in one step.
- -v also removes anonymous volumes the container created.
- Prefer docker run --rm so most containers never need manual rm.
Related guides
docker ps Command ReferenceReference for docker ps in CI: list running or all containers with -a, -q, --filter, and --format to inspect…
docker rmi Command ReferenceReference for docker rmi in CI: remove one or more images with -f to reclaim disk on runners and clear dangli…
docker system prune Command ReferenceReference for docker system prune in CI: reclaim disk by removing stopped containers, unused networks, dangli…