diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/docker/engine%2Freference%2Fcommandline%2Frm%2Findex.html | |
new repository
Diffstat (limited to 'devdocs/docker/engine%2Freference%2Fcommandline%2Frm%2Findex.html')
| -rw-r--r-- | devdocs/docker/engine%2Freference%2Fcommandline%2Frm%2Findex.html | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/devdocs/docker/engine%2Freference%2Fcommandline%2Frm%2Findex.html b/devdocs/docker/engine%2Freference%2Fcommandline%2Frm%2Findex.html new file mode 100644 index 00000000..f75661b0 --- /dev/null +++ b/devdocs/docker/engine%2Freference%2Fcommandline%2Frm%2Findex.html @@ -0,0 +1,30 @@ +<h1>docker rm</h1> <p><br></p> <p>Remove one or more containers</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker rm [OPTIONS] CONTAINER [CONTAINER...] +</pre></div> <p>For example uses of this command, refer to the <a href="#examples">examples section</a> below.</p> <h2 id="options">Options</h2> <table> <thead> <tr> <td>Name, shorthand</td> <td>Default</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td> +<code class="language-plaintext highlighter-rouge">--force</code> , <code class="language-plaintext highlighter-rouge">-f</code> +</td> <td></td> <td>Force the removal of a running container (uses SIGKILL)</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--link</code> , <code class="language-plaintext highlighter-rouge">-l</code> +</td> <td></td> <td>Remove the specified link</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--volumes</code> , <code class="language-plaintext highlighter-rouge">-v</code> +</td> <td></td> <td>Remove anonymous volumes associated with the container</td> </tr> </tbody> </table> <h2 id="examples">Examples</h2> <h3 id="remove-a-container">Remove a container</h3> <p>This removes the container referenced under the link <code class="language-plaintext highlighter-rouge">/redis</code>.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker rm /redis + +/redis +</pre></div> <h3 id="remove-a-link-specified-with---link-on-the-default-bridge-network">Remove a link specified with <code class="language-plaintext highlighter-rouge">--link</code> on the default bridge network</h3> <p>This removes the underlying link between <code class="language-plaintext highlighter-rouge">/webapp</code> and the <code class="language-plaintext highlighter-rouge">/redis</code> containers on the default bridge network, removing all network communication between the two containers. This does not apply when <code class="language-plaintext highlighter-rouge">--link</code> is used with user-specified networks.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker rm --link /webapp/redis + +/webapp/redis +</pre></div> <h3 id="force-remove-a-running-container">Force-remove a running container</h3> <p>This command force-removes a running container.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker rm --force redis + +redis +</pre></div> <p>The main process inside the container referenced under the link <code class="language-plaintext highlighter-rouge">redis</code> will receive <code class="language-plaintext highlighter-rouge">SIGKILL</code>, then the container will be removed.</p> <h3 id="remove-all-stopped-containers">Remove all stopped containers</h3> <p>Use the <a href="../container_prune/index"><code class="language-plaintext highlighter-rouge">docker container prune</code></a> command to remove all stopped containers, or refer to the <a href="../system_prune/index"><code class="language-plaintext highlighter-rouge">docker system prune</code></a> command to remove unused containers in addition to other Docker resources, such as (unused) images and networks.</p> <p>Alternatively, you can use the <code class="language-plaintext highlighter-rouge">docker ps</code> with the <code class="language-plaintext highlighter-rouge">-q</code> / <code class="language-plaintext highlighter-rouge">--quiet</code> option to generate a list of container IDs to remove, and use that list as argument for the <code class="language-plaintext highlighter-rouge">docker rm</code> command.</p> <p>Combining commands can be more flexible, but is less portable as it depends on features provided by the shell, and the exact syntax may differ depending on what shell is used. To use this approach on Windows, consider using PowerShell or Bash.</p> <p>The example below uses <code class="language-plaintext highlighter-rouge">docker ps -q</code> to print the IDs of all containers that have exited (<code class="language-plaintext highlighter-rouge">--filter status=exited</code>), and removes those containers with the <code class="language-plaintext highlighter-rouge">docker rm</code> command:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker rm $(docker ps --filter status=exited -q) +</pre></div> <p>Or, using the <code class="language-plaintext highlighter-rouge">xargs</code> Linux utility;</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter status=exited -q | xargs docker rm +</pre></div> <h3 id="remove-a-container-and-its-volumes">Remove a container and its volumes</h3> <div class="highlight"><pre class="highlight" data-language="">$ docker rm -v redis +redis +</pre></div> <p>This command removes the container and any volumes associated with it. Note that if a volume was specified with a name, it will not be removed.</p> <h3 id="remove-a-container-and-selectively-remove-volumes">Remove a container and selectively remove volumes</h3> <div class="highlight"><pre class="highlight" data-language="">$ docker create -v awesome:/foo -v /bar --name hello redis +hello + +$ docker rm -v hello +</pre></div> <p>In this example, the volume for <code class="language-plaintext highlighter-rouge">/foo</code> remains intact, but the volume for <code class="language-plaintext highlighter-rouge">/bar</code> is removed. The same behavior holds for volumes inherited with <code class="language-plaintext highlighter-rouge">--volumes-from</code>.</p> <div class="_attribution"> + <p class="_attribution-p"> + © 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br> + <a href="https://docs.docker.com/engine/reference/commandline/rm/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/rm/</a> + </p> +</div> |
