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

我试过以下几种方法:

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

以及以下几点:

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

得到以下错误:

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

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

Remove one or more images

当前回答

下面将删除所有<none>图像

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

您可以通过将docker rmi更改为docker rmi -f来强制删除,尽管我不建议这样做。

一些<none>的图像可能与其他图像相关,所以为了安全起见,不要使用-f标签。

其他回答

您可以检查过滤器是否“悬空”不再工作

$ docker images -f “dangling=true” -q
Error response from daemon: Invalid filter 'dangling'

使用docker系统修剪删除悬空图像

$ docker system prune
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all dangling build cache
Are you sure you want to continue? [y/N]

你可以用——force表示不提示确认

$ docker system prune --force

要删除所有没有图像的图像,我们必须确保我们删除了所有停止的容器,它们可以使用 运行:

docker rm $(docker ps -a -q)

然后我们可以删除所有图像:

docker image prune

它简单明了,

我花了3天时间才理解这个简单明了的错误。

docker映像未成功构建

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

然后我从Dockerfile中删除了第8行,这次成功了。

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

它说成功标记dem:expo,这一行是imp在docker进程。

运行以下命令,使用docker rmi删除映像

docker images --filter "dangling=true"      

try

docker rmi -f $(docker images -a | awk 'NR> 1 || $2 = "<none>" {print $3}') ,而可能有更干净的命令

更新