docker commands


docker rm

Remove one or more containers. Stopped ones go straight away; running ones need -f.

docker rm <container>
Save

Angle brackets are yours to fill in. Windows, Linux, macOS.

Examples for docker rm

  • Remove all stopped containers

    docker container prune
    Save

    Removes every container that is not running and prints how much space it freed. Asks to confirm; -f skips the question.

    dockertoolcontainersubcommandprunestopped ones only
  • Stop and remove a running container

    docker rm -f <container>
    Save

    One step instead of docker stop then docker rm. -f kills the container rather than asking it to stop, so use docker stop first if it needs to shut down cleanly.

    Data that is in the container and not in a volume is lost.

    dockertoolrmsubcommand-feven if running<container>argument
  • Remove every container, running or not

    docker rm -f $(docker ps -aq)
    Save

    docker ps -aq prints the id of every container; docker rm -f removes each. If there are no containers, docker rm complains that it needs an argument, which is harmless. Not for PowerShell, which uses a different syntax.

    Removes every container on this machine, including ones from other projects.

    dockertoolrmsubcommand-fflag$(docker ps -aq)every container's id
  • Remove a container and its anonymous volumes

    docker rm -v <container>
    Save

    Without -v, anonymous volumes are left behind and use disk space. Named volumes are never removed this way: use docker volume rm.

    dockertoolrmsubcommand-vand its anonymous volumes<container>argument

Flags

--force -f
Stop a running container, then remove it.The container gets no time to shut down cleanly, and anything not in a volume is lost.
--volumes -v
Also remove the anonymous volumes the container created. Named volumes stay.