简体   繁体   中英

Docker disk memory : can I remove intermediate images?

I'm running out of disk memory.

If I run docker images , I get a lot of results:

app_mongodb   latest              355f8f37c385        17 hours ago        568.1 MB
app_web       latest              a31db2244a8b        18 hours ago        868.2 MB
<none>                    <none>              71e586165d46        18 hours ago        568.1 MB
<none>                    <none>              422c281541d3        18 hours ago        568.1 MB
<none>                    <none>              1b16da634fa1        18 hours ago        535.4 MB
website_web               latest              e4442589e2f4        2 days ago          793.6 MB
<none>                    <none>              5445f9b915e6        3 days ago          535.4 MB
<none>                    <none>              e825b94d5938        3 days ago          868 MB
<none>                    <none>              ea1ddc53d17f        3 days ago          535.4 MB
<none>                    <none>              90531b8bd2d3        5 days ago          855.6 MB
<none>                    <none>              774895648397        5 days ago          535.4 MB
<none>                    <none>              0f474dc179c4        5 days ago          855.6 MB
<none>                    <none>              37cd4d180580        5 days ago          535.4 MB
<none>                    <none>              5f701c2e3fac        5 days ago          535.4 MB
<none>                    <none>              6837158ac191        5 days ago          535.4 MB
<none>                    <none>              f3eecd70620e        5 days ago          535.4 MB
<none>                    <none>              27b3e1701f05        5 days ago          535.4 MB
<none>                    <none>              64763f09b1d4        5 days ago          535.4 MB
<none>                    <none>              b58542e468e6        5 days ago          855.6 MB
app2_web          latest              01c45018b686        5 days ago          645.5 MB
redis                     latest              e4a35914679d        11 days ago         182.9 MB
<none>                    <none>              8d6737f884f8        12 days ago         854.7 MB
<none>                    <none>              27f7742e8b2b        2 weeks ago         792.1 MB
api_web                   latest              59ec56265675        2 weeks ago         906.4 MB
<none>                    <none>              33c328f5a271        2 weeks ago         782.2 MB
<none>                    <none>              53d4ad25e6c2        2 weeks ago         782.1 MB
<none>                    <none>              01ac14f597ba        2 weeks ago         854 MB
app3_web           latest              2aaa4675cc58        3 weeks ago         929.9 MB
<none>                    <none>              bde15910281e        3 weeks ago         789.5 MB
postgres                  latest              ecd991538a0f        4 weeks ago         265.5 MB
app4_web                latest              c8b0de070d78        7 weeks ago         1.088 GB
<none>                    <none>              67e3ef67081b        7 weeks ago         859.2 MB
<none>                    <none>              451229f8dedb        7 weeks ago         859.2 MB
server_web                latest              72bd5165f262        9 weeks ago         665.4 MB
<none>                    <none>              c7f0d2b67986        9 weeks ago         660.9 MB
app5_web               latest              7477b8e5ef63        3 months ago        690 MB
<none>                    <none>              ee7de82e0cf0        3 months ago        856.7 MB
mdillon/postgis           latest              ee2a84576d15        3 months ago        600.2 MB
<none>                    <none>              d8ee634a8581        4 months ago        685.3 MB
memcached                 latest              5fdd5c36cc9a        4 months ago        126.1 MB
app6_web              latest              813fb5eac7d1        5 months ago        823.7 MB
app7_web          latest              3b6a87b67359        5 months ago        645.5 MB
node                      argon               3b6a87b67359        5 months ago        645.5 MB
mongo                     latest              48b8b08dca4d        6 months ago        366.4 MB
ruby                      2.2.1               aca1c061bdd2        23 months ago       775.1 MB

I know what all the named dockers correspond to, I can easily manage them and remove those I don't need anymore. But they are not majority!

Regarding the other ones, I guess they are intermediate dockers.

I wonder if I remove those, will the named one be broken or it's simply that if I rebuild them (eg. with the --no-cache option), docker will have to re-download them? (which is fine)

Eg. Does a docker based on the ruby one needs it to start or only to build?

These are probably images you built in the past, but then when you rebuilt the image, the relevant tag moved to another image, leaving these images untagged. Thus they show up as <none> <none> .

Looking at a sampling of your output, I'd guess a lot of them are old builds of app_mongodb:latest and app_web:latest . Based on the sizes.

app_mongodb       latest    355f8f37c385    17 hours ago    568.1 MB
app_web           latest    a31db2244a8b    18 hours ago    868.2 MB
<none>            <none>    71e586165d46    18 hours ago    568.1 MB
<none>            <none>    422c281541d3    18 hours ago    568.1 MB
<none>            <none>    1b16da634fa1    18 hours ago    535.4 MB
website_web       latest    e4442589e2f4    2 days ago      793.6 MB
<none>            <none>    5445f9b915e6    3 days ago      535.4 MB
<none>            <none>    e825b94d5938    3 days ago      868 MB
<none>            <none>    ea1ddc53d17f    3 days ago      535.4 MB
<none>            <none>    90531b8bd2d3    5 days ago      855.6 MB
<none>            <none>    774895648397    5 days ago      535.4 MB
<none>            <none>    0f474dc179c4    5 days ago      855.6 MB
<none>            <none>    37cd4d180580    5 days ago      535.4 MB
<none>            <none>    5f701c2e3fac    5 days ago      535.4 MB
<none>            <none>    6837158ac191    5 days ago      535.4 MB
<none>            <none>    f3eecd70620e    5 days ago      535.4 MB
<none>            <none>    27b3e1701f05    5 days ago      535.4 MB
<none>            <none>    64763f09b1d4    5 days ago      535.4 MB
<none>            <none>    b58542e468e6    5 days ago      855.6 MB

It is most likely safe to delete them. If you try to delete them and they are being used by a container or another image, then Docker will complain about that.

In recent versions of Docker (I believe >= 1.13) you can use the prune command to clean up images not referenced by an image or container.

docker image prune

in the newer docker versions, you can simply do:

docker image prune

refer to: https://docs.docker.com/engine/reference/commandline/image_prune/#description

Using docker images -f dangling=true -q we can find <none><none> images. Then we can delete them using below command,

docker rmi -f $(docker images -f dangling=true -q --no-trunc)

We may need -f option to delete them forcefully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM