Docker remove TAG images

2019-03-08 02:46发布

root@server:~# docker images -a        
REPOSITORY              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>                  <none>              5e2dfc857e73        5 days ago          261.6 MB
<none>                  <none>              d053e988f23d        5 days ago          261.6 MB
<none>                  <none>              1d5d4a2d89eb        5 days ago          261.6 MB
<none>                  <none>              ea0d189fdb19        5 days ago          100.5 MB
<none>                  <none>              26c6175962b3        5 days ago          100.5 MB
<none>                  <none>              73d5cec4a0b3        5 days ago          100.5 MB
<none>                  <none>              e19590e1bac1        5 days ago          100.5 MB

I've tried the following:

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

And the following:

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

Get the following error:

docker: "rmi" requires a minimum of 1 argument.
See 'docker rmi --help'.

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

标签: docker
15条回答
老娘就宠你
2楼-- · 2019-03-08 03:41

According to the docker documentation you can list only untagged (dangling) images with

$ docker images -f "dangling=true"

and redirect them to docker rmi command like that:

$ docker rmi $(docker images -f "dangling=true" -q) --force

Notice -q param thats only show numeric IDs of containers.

查看更多
太酷不给撩
3楼-- · 2019-03-08 03:45

Remove images which have none as the repository name using the following:

docker rmi $(docker images | grep "^<none" | awk '{print $3}')

Remove images which have none tag or repository name:

docker rmi $(docker images | grep "none" | awk '{print $3}')
查看更多
【Aperson】
4楼-- · 2019-03-08 03:45

This is an extension of tansadio's answer:

If you are getting following error:

Error response from daemon: conflict: unable to delete <> (must be forced) - image is being used by stopped container <>

You can force it with --force:

docker images | grep none | awk '{ print $3; }' | xargs docker rmi --force
查看更多
登录 后发表回答