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

The below command is working for me. this is just simple grep "" images and get the docker image id and removed all the images. Simple single command as it has to.

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

查看更多
Viruses.
3楼-- · 2019-03-08 03:27

Just remove the images using their IDs:

# docker rmi 5e2dfc857e73 d053e988f23d ...
查看更多
Explosion°爆炸
4楼-- · 2019-03-08 03:29

try

docker rmi -f $(docker images -a | awk 'NR> 1 || $2 = "<none>" {print $3}') , while there may be cleaner commands

Updated

查看更多
Anthone
5楼-- · 2019-03-08 03:30
docker rmi $(docker images -a -q)

Stated the following images where in use. I think this command gets rid of unwanted images.

查看更多
趁早两清
6楼-- · 2019-03-08 03:31

You can try and list only untagged images (ones with no labels, or with label with no tag):

docker images -q -a | xargs docker inspect --format='{{.Id}}{{range $rt := .RepoTags}} {{$rt}} {{end}}'|grep -v ':'

However, some of those untagged images might be needed by others.

I prefer removing only dangling images:

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

As I mentioned for for docker 1.13+ in Sept. 2016 in "How to remove old and unused Docker images", you can also do the image prune command:

docker image prune

That being said, Janaka Bandara mentions in the comments:

This did not remove <none>-tagged images for me (e.g. foo/bar:<none>); I had to use docker images --digests and docker rmi foo/bar@<digest>

Janaka references "How to Remove a Signed Image with a Tag" from Paul V. Novarese:

# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
pvnovarese/mprime        latest              459769dbc7a1        5 days ago          4.461 MB
pvnovarese/mprime        <none>              459769dbc7a1        5 days ago          4.461 MB

Diagnostic Steps

You can see the difference in these two entries if you use the --digests=true option (the untagged entry has the Docker Content Trust signature digest):

# docker images --digests=true
REPOSITORY               TAG                 DIGEST                                                                    IMAGE ID            CREATED             SIZE
pvnovarese/mprime        latest              <none>                                                                    459769dbc7a1        5 days ago          4.461 MB
pvnovarese/mprime        <none>              sha256:0b315a681a6b9f14f93ab34f3c744fd547bda30a03b55263d93861671fa33b00   459769dbc7a1        5 days ago     

Note that Paul also mentions moby issue 18892:

After pulling a signed image, there is an "extra" entry (with tag <none>) in "docker images" output.
This makes it difficult to rmi the image (you have to force it, or else first delete the properly-tagged entry, or delete by digest.

查看更多
▲ chillily
7楼-- · 2019-03-08 03:34

Its simple and clear,

Even I took 3 days to understand this simple and crisp error.

The docker image is not built successfully

Step 7/13 : COPY jupyter_notebook_config.py /root/.jupyter/
 ---> bf29ce6fe6dc
Step 8/13 : COPY notebooks /notebooks
COPY failed: stat /var/lib/docker/tmp/docker-builder776981166/notebooks: no such file or directory
anarchist@anarchist-desktop:~/Documents/sam/dockerDem$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              bf29ce6fe6dc        9 seconds ago       1.27GB
ubuntu              16.04               a51debf7e1eb        3 weeks ago         116MB

Then I removed the 8th line from Dockerfile, it was signal success this time.

Successfully built b6724370f8ca
Successfully tagged dem:expo
anarchist@anarchist-desktop:~/Documents/sam/dockerDem$ docker run -it -p 8888:8888 dem:expo
[I 06:11:38.984 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 06:11:39.011 NotebookApp] Serving notebooks from local directory: /
[I 06:11:39.011 NotebookApp] The Jupyter Notebook is running at:
[I 06:11:39.011 NotebookApp] http://(296d81166725 or 127.0.0.1):8888/?token=496feb282ef749c05277ef57a51e8a56fedb1c6b337b9f92

It says successfully tagged dem:expo, this line is imp during docker process.

查看更多
登录 后发表回答