summaryrefslogtreecommitdiff
path: root/devdocs/docker/engine%2Freference%2Fcommandline%2Fimage_prune%2Findex.html
blob: d321382dab7b00b915a2d976465c7cbe264c678d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<h1>docker image prune</h1>  <p><br></p> <p>Remove unused images</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker image prune [OPTIONS]
</pre></div> <p>Refer to the <a href="#options">options section</a> for an overview of available <a href="#options"><code class="language-plaintext highlighter-rouge">OPTIONS</code></a> for this command.</p> <h2 id="description">Description</h2> <p name="extended-description">Remove all dangling images. If <code class="language-plaintext highlighter-rouge">-a</code> is specified, will also remove all images not referenced by any container.</p> <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">--all</code> , <code class="language-plaintext highlighter-rouge">-a</code>
</td> <td></td> <td>Remove all unused images, not just dangling ones</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--filter</code></td> <td></td> <td>Provide filter values (e.g. 'until=&lt;timestamp&gt;')</td> </tr> <tr> <td>
<code class="language-plaintext highlighter-rouge">--force</code> , <code class="language-plaintext highlighter-rouge">-f</code>
</td> <td></td> <td>Do not prompt for confirmation</td> </tr>  </tbody> </table>  <h2 id="examples">Examples</h2> <p>Example output:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker image prune -a

WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: alpine:latest
untagged: alpine@sha256:3dcdb92d7432d56604d4545cbd324b14e647b313626d99b889d0626de158f73a
deleted: sha256:4e38e38c8ce0b8d9041a9c4fefe786631d1416225e13b0bfe8cfa2321aec4bba
deleted: sha256:4fe15f8d0ae69e169824f25f1d4da3015a48feeeeebb265cd2e328e15c6a869f
untagged: alpine:3.3
untagged: alpine@sha256:4fa633f4feff6a8f02acfc7424efd5cb3e76686ed3218abf4ca0fa4a2a358423
untagged: my-jq:latest
deleted: sha256:ae67841be6d008a374eff7c2a974cde3934ffe9536a7dc7ce589585eddd83aff
deleted: sha256:34f6f1261650bc341eb122313372adc4512b4fceddc2a7ecbb84f0958ce5ad65
deleted: sha256:cf4194e8d8db1cb2d117df33f2c75c0369c3a26d96725efb978cc69e046b87e7
untagged: my-curl:latest
deleted: sha256:b2789dd875bf427de7f9f6ae001940073b3201409b14aba7e5db71f408b8569e
deleted: sha256:96daac0cb203226438989926fc34dd024f365a9a8616b93e168d303cfe4cb5e9
deleted: sha256:5cbd97a14241c9cd83250d6b6fc0649833c4a3e84099b968dd4ba403e609945e
deleted: sha256:a0971c4015c1e898c60bf95781c6730a05b5d8a2ae6827f53837e6c9d38efdec
deleted: sha256:d8359ca3b681cc5396a4e790088441673ed3ce90ebc04de388bfcd31a0716b06
deleted: sha256:83fc9ba8fb70e1da31dfcc3c88d093831dbd4be38b34af998df37e8ac538260c
deleted: sha256:ae7041a4cc625a9c8e6955452f7afe602b401f662671cea3613f08f3d9343b35
deleted: sha256:35e0f43a37755b832f0bbea91a2360b025ee351d7309dae0d9737bc96b6d0809
deleted: sha256:0af941dd29f00e4510195dd00b19671bc591e29d1495630e7e0f7c44c1e6a8c0
deleted: sha256:9fc896fc2013da84f84e45b3096053eb084417b42e6b35ea0cce5a3529705eac
deleted: sha256:47cf20d8c26c46fff71be614d9f54997edacfe8d46d51769706e5aba94b16f2b
deleted: sha256:2c675ee9ed53425e31a13e3390bf3f539bf8637000e4bcfbb85ee03ef4d910a1

Total reclaimed space: 16.43 MB
</pre></div> <h3 id="filtering">Filtering</h3> <p>The filtering flag (<code class="language-plaintext highlighter-rouge">--filter</code>) format is of “key=value”. If there is more than one filter, then pass multiple flags (e.g., <code class="language-plaintext highlighter-rouge">--filter "foo=bar" --filter "bif=baz"</code>)</p> <p>The currently supported filters are:</p> <ul> <li>until (<code class="language-plaintext highlighter-rouge">&lt;timestamp&gt;</code>) - only remove images created before given timestamp</li> <li>label (<code class="language-plaintext highlighter-rouge">label=&lt;key&gt;</code>, <code class="language-plaintext highlighter-rouge">label=&lt;key&gt;=&lt;value&gt;</code>, <code class="language-plaintext highlighter-rouge">label!=&lt;key&gt;</code>, or <code class="language-plaintext highlighter-rouge">label!=&lt;key&gt;=&lt;value&gt;</code>) - only remove images with (or without, in case <code class="language-plaintext highlighter-rouge">label!=...</code> is used) the specified labels.</li> </ul> <p>The <code class="language-plaintext highlighter-rouge">until</code> filter can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. <code class="language-plaintext highlighter-rouge">10m</code>, <code class="language-plaintext highlighter-rouge">1h30m</code>) computed relative to the daemon machine’s time. Supported formats for date formatted time stamps include RFC3339Nano, RFC3339, <code class="language-plaintext highlighter-rouge">2006-01-02T15:04:05</code>, <code class="language-plaintext highlighter-rouge">2006-01-02T15:04:05.999999999</code>, <code class="language-plaintext highlighter-rouge">2006-01-02Z07:00</code>, and <code class="language-plaintext highlighter-rouge">2006-01-02</code>. The local timezone on the daemon will be used if you do not provide either a <code class="language-plaintext highlighter-rouge">Z</code> or a <code class="language-plaintext highlighter-rouge">+-00:00</code> timezone offset at the end of the timestamp. When providing Unix timestamps enter seconds[.nanoseconds], where seconds is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a fraction of a second no more than nine digits long.</p> <p>The <code class="language-plaintext highlighter-rouge">label</code> filter accepts two formats. One is the <code class="language-plaintext highlighter-rouge">label=...</code> (<code class="language-plaintext highlighter-rouge">label=&lt;key&gt;</code> or <code class="language-plaintext highlighter-rouge">label=&lt;key&gt;=&lt;value&gt;</code>), which removes images with the specified labels. The other format is the <code class="language-plaintext highlighter-rouge">label!=...</code> (<code class="language-plaintext highlighter-rouge">label!=&lt;key&gt;</code> or <code class="language-plaintext highlighter-rouge">label!=&lt;key&gt;=&lt;value&gt;</code>), which removes images without the specified labels.</p> <blockquote> <p><strong>Predicting what will be removed</strong></p> <p>If you are using positive filtering (testing for the existence of a label or that a label has a specific value), you can use <code class="language-plaintext highlighter-rouge">docker image ls</code> with the same filtering syntax to see which images match your filter.</p> <p>However, if you are using negative filtering (testing for the absence of a label or that a label does <em>not</em> have a specific value), this type of filter does not work with <code class="language-plaintext highlighter-rouge">docker image ls</code> so you cannot easily predict which images will be removed. In addition, the confirmation prompt for <code class="language-plaintext highlighter-rouge">docker image prune</code> always warns that <em>all</em> dangling images will be removed, even if you are using <code class="language-plaintext highlighter-rouge">--filter</code>.</p> </blockquote> <p>The following removes images created before <code class="language-plaintext highlighter-rouge">2017-01-04T00:00:00</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedAt}}\t{{.Size}}'
REPOSITORY          TAG                 IMAGE ID            CREATED AT                      SIZE
foo                 latest              2f287ac753da        2017-01-04 13:42:23 -0800 PST   3.98 MB
alpine              latest              88e169ea8f46        2016-12-27 10:17:25 -0800 PST   3.98 MB
busybox             latest              e02e811dd08f        2016-10-07 14:03:58 -0700 PDT   1.09 MB

$ docker image prune -a --force --filter "until=2017-01-04T00:00:00"

Deleted Images:
untagged: alpine:latest
untagged: alpine@sha256:dfbd4a3a8ebca874ebd2474f044a0b33600d4523d03b0df76e5c5986cb02d7e8
untagged: busybox:latest
untagged: busybox@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912
deleted: sha256:e02e811dd08fd49e7f6032625495118e63f597eb150403d02e3238af1df240ba
deleted: sha256:e88b3f82283bc59d5e0df427c824e9f95557e661fcb0ea15fb0fb6f97760f9d9

Total reclaimed space: 1.093 MB

$ docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedAt}}\t{{.Size}}'

REPOSITORY          TAG                 IMAGE ID            CREATED AT                      SIZE
foo                 latest              2f287ac753da        2017-01-04 13:42:23 -0800 PST   3.98 MB
</pre></div> <p>The following removes images created more than 10 days (<code class="language-plaintext highlighter-rouge">240h</code>) ago:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
foo                 latest              2f287ac753da        14 seconds ago      3.98 MB
alpine              latest              88e169ea8f46        8 days ago          3.98 MB
debian              jessie              7b0a06c805e8        2 months ago        123 MB
busybox             latest              e02e811dd08f        2 months ago        1.09 MB
golang              1.7.0               138c2e655421        4 months ago        670 MB

$ docker image prune -a --force --filter "until=240h"

Deleted Images:
untagged: golang:1.7.0
untagged: golang@sha256:6765038c2b8f407fd6e3ecea043b44580c229ccfa2a13f6d85866cf2b4a9628e
deleted: sha256:138c2e6554219de65614d88c15521bfb2da674cbb0bf840de161f89ff4264b96
deleted: sha256:ec353c2e1a673f456c4b78906d0d77f9d9456cfb5229b78c6a960bfb7496b76a
deleted: sha256:fe22765feaf3907526b4921c73ea6643ff9e334497c9b7e177972cf22f68ee93
deleted: sha256:ff845959c80148421a5c3ae11cc0e6c115f950c89bc949646be55ed18d6a2912
deleted: sha256:a4320831346648c03db64149eafc83092e2b34ab50ca6e8c13112388f25899a7
deleted: sha256:4c76020202ee1d9709e703b7c6de367b325139e74eebd6b55b30a63c196abaf3
deleted: sha256:d7afd92fb07236c8a2045715a86b7d5f0066cef025018cd3ca9a45498c51d1d6
deleted: sha256:9e63c5bce4585dd7038d830a1f1f4e44cb1a1515b00e620ac718e934b484c938
untagged: debian:jessie
untagged: debian@sha256:c1af755d300d0c65bb1194d24bce561d70c98a54fb5ce5b1693beb4f7988272f
deleted: sha256:7b0a06c805e8f23807fb8856621c60851727e85c7bcb751012c813f122734c8d
deleted: sha256:f96222d75c5563900bc4dd852179b720a0885de8f7a0619ba0ac76e92542bbc8

Total reclaimed space: 792.6 MB

$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
foo                 latest              2f287ac753da        About a minute ago   3.98 MB
alpine              latest              88e169ea8f46        8 days ago           3.98 MB
busybox             latest              e02e811dd08f        2 months ago         1.09 MB
</pre></div> <p>The following example removes images with the label <code class="language-plaintext highlighter-rouge">deprecated</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker image prune --filter="label=deprecated"
</pre></div> <p>The following example removes images with the label <code class="language-plaintext highlighter-rouge">maintainer</code> set to <code class="language-plaintext highlighter-rouge">john</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker image prune --filter="label=maintainer=john"
</pre></div> <p>This example removes images which have no <code class="language-plaintext highlighter-rouge">maintainer</code> label:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker image prune --filter="label!=maintainer"
</pre></div> <p>This example removes images which have a maintainer label not set to <code class="language-plaintext highlighter-rouge">john</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker image prune --filter="label!=maintainer=john"
</pre></div> <blockquote> <p><strong>Note</strong></p> <p>You are prompted for confirmation before the <code class="language-plaintext highlighter-rouge">prune</code> removes anything, but you are not shown a list of what will potentially be removed. In addition, <code class="language-plaintext highlighter-rouge">docker image ls</code> does not support negative filtering, so it difficult to predict what images will actually be removed.</p> </blockquote> <h2 id="parent-command">Parent command</h2> <table> <thead> <tr> <th style="text-align: left">Command</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><a href="../image/index">docker image</a></td> <td style="text-align: left">Manage images</td> </tr> </tbody> </table> <h2 id="related-commands">Related commands</h2> <table> <thead> <tr> <td>Command</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td><a href="../image_build/index">docker image build</a></td> <td>Build an image from a Dockerfile</td> </tr> <tr> <td><a href="../image_history/index">docker image history</a></td> <td>Show the history of an image</td> </tr> <tr> <td><a href="../image_import/index">docker image import</a></td> <td>Import the contents from a tarball to create a filesystem image</td> </tr> <tr> <td><a href="../image_inspect/index">docker image inspect</a></td> <td>Display detailed information on one or more images</td> </tr> <tr> <td><a href="../image_load/index">docker image load</a></td> <td>Load an image from a tar archive or STDIN</td> </tr> <tr> <td><a href="../image_ls/index">docker image ls</a></td> <td>List images</td> </tr> <tr> <td><a href="index">docker image prune</a></td> <td>Remove unused images</td> </tr> <tr> <td><a href="../image_pull/index">docker image pull</a></td> <td>Pull an image or a repository from a registry</td> </tr> <tr> <td><a href="../image_push/index">docker image push</a></td> <td>Push an image or a repository to a registry</td> </tr> <tr> <td><a href="../image_rm/index">docker image rm</a></td> <td>Remove one or more images</td> </tr> <tr> <td><a href="../image_save/index">docker image save</a></td> <td>Save one or more images to a tar archive (streamed to STDOUT by default)</td> </tr> <tr> <td><a href="../image_tag/index">docker image tag</a></td> <td>Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE</td> </tr> </tbody> </table> <div class="_attribution">
  <p class="_attribution-p">
    &copy; 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/image_prune/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/image_prune/</a>
  </p>
</div>