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:18

docker rmi -f $(docker images -a|awk 'NR > 1 && $2 == "" {print $3}')

查看更多
三岁会撩人
3楼-- · 2019-03-08 03:20

I have found docker image prune -f most useful and I use it all the time during my day to day work, using the tag -f will not prompt for confirmation. More details here

查看更多
Luminary・发光体
4楼-- · 2019-03-08 03:20

To remove dangling images please use :

docker image rm $(docker images --format "{{.ID}}" --filter "dangling=true")

Please refer to my answer here for a more detailed description : https://unix.stackexchange.com/a/445664/292327

查看更多
Ridiculous、
5楼-- · 2019-03-08 03:25

You can go docker rmi $(docker images -f "dangling=true" -q). See the images documentation for more options.

$ docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
<none>                      <none>              94870cda569b        4 seconds ago       673MB
python                      2.7                 320a06f42b5f        10 days ago         673MB
mysql                       latest              e799c7f9ae9c        2 months ago        407MB
gcavalcante8808/semaphore   latest              86e863e11461        2 months ago        537MB
redis                       latest              e32ef7250bc1        2 months ago        184MB
rabbitmq                    3.6.9-management    7e69e14cc496        2 months ago        179MB
rabbitmq                    3.6.9               eb2e4968538a        2 months ago        179MB
jordan/rundeck              latest              6d40b57b1572        2 months ago        660MB
rabbitmq                    3.5.6-management    dbfe8d18809a        19 months ago       304MB

$ docker rmi $(docker images --format '{{.ID}}' --filter=dangling=true)
Deleted: sha256:94870cda569b8cf5f42be25af107d464c993b4502a1472c1679bf2d213b6c0a6
查看更多
We Are One
6楼-- · 2019-03-08 03:26
docker images | grep none | awk '{ print $3; }' | xargs docker rmi

You can try this simply

查看更多
Anthone
7楼-- · 2019-03-08 03:27

docker image prune removes all dangling images (those with tag none). docker image prune -a would also remove any images that have no container that uses them.

The difference between dangling and unused images is explained in this stackoverflow thread.

查看更多
登录 后发表回答