docker rm
Delete stopped containers, force-remove a running one with -f, and let --rm clean up one-off containers for you.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
docker rm job -
docker rm old -
docker rm -f web -
docker ps -a -
docker run --rm alpine echo "gone when done" -
docker ps -a
How it works
docker rm NAME deletes a stopped container: its own files go with it, and its name can be used again. A running one is refused — stop it first, or use -f.
Removing a container does not remove its image or its named volumes: docker images and docker volume ls still show them.
Syntax
docker rm [-f] CONTAINER...
Options
| Option | What it does |
|---|---|
CONTAINER... | one or more containers, by name or ID |
-f | force: stop it first if it is running |
docker run --rm | with docker run: delete the container as soon as it exits |
Good to know
- "The container name is already in use": the old one still exists.
docker rmit (or pick another name) beforedocker run --nameagain. - Before deleting a database container, check its data lives in a volume:
docker inspect NAMEshows its mounts.