...
1# rm
2
3<!---MARKER_GEN_START-->
4Remove one or more containers
5
6### Aliases
7
8`docker container rm`, `docker container remove`, `docker rm`
9
10### Options
11
12| Name | Type | Default | Description |
13|:------------------------------------------|:-----|:--------|:--------------------------------------------------------|
14| [`-f`](#force), [`--force`](#force) | | | Force the removal of a running container (uses SIGKILL) |
15| [`-l`](#link), [`--link`](#link) | | | Remove the specified link |
16| [`-v`](#volumes), [`--volumes`](#volumes) | | | Remove anonymous volumes associated with the container |
17
18
19<!---MARKER_GEN_END-->
20
21## Examples
22
23### Remove a container
24
25This removes the container referenced under the link `/redis`.
26
27```console
28$ docker rm /redis
29
30/redis
31```
32
33### <a name="link"></a> Remove a link specified with `--link` on the default bridge network (--link)
34
35This removes the underlying link between `/webapp` and the `/redis`
36containers on the default bridge network, removing all network communication
37between the two containers. This does not apply when `--link` is used with
38user-specified networks.
39
40```console
41$ docker rm --link /webapp/redis
42
43/webapp/redis
44```
45
46### <a name="force"></a> Force-remove a running container (--force)
47
48This command force-removes a running container.
49
50```console
51$ docker rm --force redis
52
53redis
54```
55
56The main process inside the container referenced under the link `redis` will receive
57`SIGKILL`, then the container will be removed.
58
59### Remove all stopped containers
60
61Use the [`docker container prune`](container_prune.md) command to remove all
62stopped containers, or refer to the [`docker system prune`](system_prune.md)
63command to remove unused containers in addition to other Docker resources, such
64as (unused) images and networks.
65
66Alternatively, you can use the `docker ps` with the `-q` / `--quiet` option to
67generate a list of container IDs to remove, and use that list as argument for
68the `docker rm` command.
69
70Combining commands can be more flexible, but is less portable as it depends
71on features provided by the shell, and the exact syntax may differ depending on
72what shell is used. To use this approach on Windows, consider using PowerShell
73or Bash.
74
75The example below uses `docker ps -q` to print the IDs of all containers that
76have exited (`--filter status=exited`), and removes those containers with
77the `docker rm` command:
78
79```console
80$ docker rm $(docker ps --filter status=exited -q)
81```
82
83Or, using the `xargs` Linux utility:
84
85```console
86$ docker ps --filter status=exited -q | xargs docker rm
87```
88
89### <a name="volumes"></a> Remove a container and its volumes (-v, --volumes)
90
91```console
92$ docker rm --volumes redis
93redis
94```
95
96This command removes the container and any volumes associated with it.
97Note that if a volume was specified with a name, it will not be removed.
98
99### Remove a container and selectively remove volumes
100
101```console
102$ docker create -v awesome:/foo -v /bar --name hello redis
103hello
104
105$ docker rm -v hello
106```
107
108In this example, the volume for `/foo` remains intact, but the volume for
109`/bar` is removed. The same behavior holds for volumes inherited with
110`--volumes-from`.
View as plain text