我在OS X 10.8.4(Mountain Lion)下运行Vagrant下的Docker,每当我尝试删除保存的图像时,都会出现错误:

$ docker rmi some-image-id
2013/07/15 hh:mm:ss unexpected JSON input

根据rmi帮助,正确的语法是docker rmi IMAGE[IMAGE…],我不知道该怎么做。

如何删除图像?

$ docker version
Client version: 0.4.8
Server version: 0.4.8
Go version: go1.1

 

$docker info
Containers: 1
Images: 3

有趣的是,当我运行docker ps时,根本没有容器出现。运行docker图像显示四(4)个基本图像和一(1)个节点图像。


当前回答

我的问题是我有两张同名的照片解决方案是在名称或id之后添加标记

sudo docker rmi <NAME>:<TAG>

ex:

sudo docker rmi php:7.0.4-fpm

其他回答

更新,正如VonC在如何删除旧Docker容器中所评论的。

使用Docker 1.13(2016年第4季度),您现在可以:

docker系统prune将删除所有未使用的数据(即,按顺序:容器停止、没有容器的卷和没有容器的图像)。

请参阅PR 26108和commit 86de7c0,它们引入了一些新命令,以帮助可视化Docker守护程序数据在磁盘上占用的空间,并允许轻松清理“不需要的”多余空间。

docker system prune

WARNING! This will remove:
    - all stopped containers
    - all volumes not used by at least one container
    - all images without at least one container associated to them
Are you sure you want to continue? [y/N] y

Docker提供了一些删除图像的命令。

显示/删除图像:

docker images
docker images -a # All images
docker images --no-trunc # List the full length image IDs

docker images --filter "dangling=true" // Show unstage images
docker rmi $(docker images -f "dangling=true" -q) # Remove on unstages images

docker rmi <REPOSITORY> or <Image ID> # Remove a single image

docker image prune # Interactively remove dangling images
docker image prune -a # Remove all images

or 

docker rmi -f $(sudo docker images -a -q)

此外,您还可以使用过滤器参数删除一次:

例子:

$docker images --filter "before=<hello-world>" // It will all images before hello-world

$docker images --filter "since=<hello-world>" // It will all images since hello-world

因此,您可以像这样删除过滤器图像:

docker rmi $(docker images --filter "since=<hello-world>")
docker rmi $(docker images --filter "before=<hello-world>")

要使用图像ID从Docker中删除图像,请执行以下操作:

获取所有图像的列表docker图像标识要删除的图像的图像ID,例如:存储库标记映像ID创建的虚拟大小kweku360/java最新版本08d3a9b8e166 2周前5.733 GB`最后使用图像ID删除图像(只需要前三位数字)码头工人rmi 08d

首先,我们必须停止并删除Docker容器,这些容器与我们将要删除的Docker映像相关联。

因此,首先

docker stop container id-停止正在运行的容器docker rm container id-删除/删除容器

然后

docker rmi image id-删除/删除图像

对我来说,以下工作很好:

> docker images
REPOSITORY   TAG           IMAGE ID          CREATED             SIZE
debian       jessie        86baf4e8cde9      3 weeks ago         123MB
ubuntu       yakkety       7d3f705d307c      3 weeks ago         107MB
alpine       3.5           074d602a59d7      7 weeks ago         3.99MB

然后继续,通过运行以下命令删除图像:

> docker rmi debian:jessie
> docker rmi ubuntu:yakkety
> docker rmi alipine:3.5