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 here
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

OptionWhat it does
CONTAINER...one or more containers, by name or ID
-fforce: stop it first if it is running
docker run --rmwith 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 rm it (or pick another name) before docker run --name again.
  • Before deleting a database container, check its data lives in a volume: docker inspect NAME shows its mounts.