我在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)个节点图像。


当前回答

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>")

其他回答

使用删除所有文件

步骤1:杀死所有容器

for i in `sudo docker ps -a | awk '{ print $1 }'`; do sudo docker kill $i ; done

第2步:首先对他们进行RM

for i in `sudo docker ps -a | awk '{ print $1 }'`; do sudo docker rm $i ; done

步骤3:使用武力删除图像

for i in `sudo docker images | awk '{ print $3}'`; do  sudo docker rmi --force $i ; done

使用步骤1,以防由于子依赖关系而导致无法删除错误

尝试docker rmi节点。这应该奏效。

看到所有创建的容器就像docker ps-a一样简单。

要删除所有现有容器(而不是图像!),请运行docker rm$(docker ps-aq)

首先使用以下方法列出您的所有图像:docker图像

用于删除单个图像

使用docker rmi[image name(or)image id]//这将仅删除该特定图像

用于删除所有图像

使用docker rmi-f$(docker images-a-q)

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>")

图像:

列出图像docker图像删除一个图像docker rmi映像名称强制删除一个图像docker rmi-f映像名称

容器:

列出所有容器码头工人ps-a移除一个容器docker rm container_id强制移除一个容器docker rm-f container_id