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
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.
Frequently asked questions
docker rm Command Reference?
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.
In 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.