github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/cli/docs/reference/commandline/rm.md (about)

     1  ---
     2  title: "rm"
     3  description: "The rm command description and usage"
     4  keywords: "remove, Docker, container"
     5  ---
     6  
     7  # rm
     8  
     9  ```markdown
    10  Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]
    11  
    12  Remove one or more containers
    13  
    14  Options:
    15    -f, --force     Force the removal of a running container (uses SIGKILL)
    16        --help      Print usage
    17    -l, --link      Remove the specified link
    18    -v, --volumes   Remove anonymous volumes associated with the container
    19  ```
    20  
    21  ## Examples
    22  
    23  ### Remove a container
    24  
    25  This 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  
    35  This removes the underlying link between `/webapp` and the `/redis`
    36  containers on the default bridge network, removing all network communication
    37  between the two containers. This does not apply when `--link` is used with
    38  user-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  
    48  This command force-removes a running container.
    49  
    50  ```console
    51  $ docker rm --force redis
    52  
    53  redis
    54  ```
    55  
    56  The 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  
    61  Use the [`docker container prune`](container_prune.md) command to remove all
    62  stopped containers, or refer to the [`docker system prune`](system_prune.md)
    63  command to remove unused containers in addition to other Docker resources, such
    64  as (unused) images and networks.
    65  
    66  Alternatively, you can use the `docker ps` with the `-q` / `--quiet` option to
    67  generate a list of container IDs to remove, and use that list as argument for
    68  the `docker rm` command.
    69  
    70  Combining commands can be more flexible, but is less portable as it depends
    71  on features provided by the shell, and the exact syntax may differ depending on
    72  what shell is used. To use this approach on Windows, consider using PowerShell
    73  or Bash.
    74  
    75  The example below uses `docker ps -q` to print the IDs of all containers that
    76  have exited (`--filter status=exited`), and removes those containers with
    77  the `docker rm` command:
    78  
    79  ```console
    80  $ docker rm $(docker ps --filter status=exited -q)
    81  ```
    82  
    83  Or, 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
    93  redis
    94  ```
    95  
    96  This command removes the container and any volumes associated with it.
    97  Note 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
   103  hello
   104  
   105  $ docker rm -v hello
   106  ```
   107  
   108  In 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`.