LinuxCommandLibrary

docker-container-rm

Remove Docker containers

TLDR

Remove containers

$ docker [[rm|container rm]] [container1 container2 ...]
copy

Force remove a container
$ docker [[rm|container rm]] [[-f|--force]] [container1 container2 ...]
copy

Remove a container and its volumes
$ docker [[rm|container rm]] [[-v|--volumes]] [container]
copy

Display help
$ docker [[rm|container rm]] [[-h|--help]]
copy

SYNOPSIS

docker container rm [OPTIONS] CONTAINER [CONTAINER...]

PARAMETERS

-f, --force
    Force removal of running container using SIGKILL

-h, --help
    Print usage information

-l, --link
    Remove container link instead of container

-v, --volumes
    Remove anonymous volumes associated with container

DESCRIPTION

The docker container rm command (also available as docker rm) forcefully or gracefully deletes specified Docker containers from the system.

It is essential for cleaning up unused containers, freeing disk space, and managing container lifecycle. Containers must typically be stopped before removal; running ones require the -f flag to send SIGKILL.

Multiple containers can be targeted by ID or name, identified via docker container ls. Anonymous volumes are preserved unless -v is used, preventing data loss. Links between containers are removed with -l.

This command does not affect images, networks, or named volumes unless specified. Errors occur if containers do not exist or are in use. Use docker container prune for bulk cleanup of stopped containers.

Ideal for scripts automating deployments, ensuring no dangling resources accumulate.

CAVEATS

Running containers require -f; cannot remove if container has dependent links or active processes without force. Does not remove images or named volumes by default.

EXAMPLES

docker container rm mycontainer
Remove stopped container.

docker container rm -f $(docker container ls -aq)
Remove all containers.

EXIT CODES

0: Success.
1: Failure (e.g., container running without -f).

HISTORY

Introduced in Docker 1.0 (2013) as part of core CLI. Evolved with subcommand restructuring in Docker 1.13 (2017) to docker container rm; docker rm remains alias. Enhanced volume handling in later versions.

SEE ALSO

docker-container-ls(1), docker-container-stop(1), docker-container-prune(1), docker-rm(1)

Copied to clipboard