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

其他回答

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

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

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

下面是一个shell脚本,用于删除标记(命名)的图像及其容器。另存为docker rmi并使用“docker rmi-my image name”运行

#!/bin/bash

IMAGE=$1

if [ "$IMAGE" == "" ] ; then
  echo "Missing image argument"
  exit 2
fi

docker ps -qa -f "ancestor=$IMAGE" | xargs docker rm
docker rmi $IMAGE

对于1.13及更高版本:

docker image rm [OPTIONS] IMAGE [IMAGE...]

比较:

docker图像rm和docker rmi的文档,

[选项]似乎没有什么不同。

--force , -f        Force removal of the image
--no-prune          Do not delete untagged parents

发件人:Docker 1.13简介

CLI已重组在Docker 1.13中,我们重新组合了每个命令,使其位于与之交互的逻辑对象之下。例如,list和start of containers现在是docker container的子命令,history是docker image的子命令。这些更改让我们清理了Docker CLI语法,改进了帮助文本,使Docker更易于使用。旧的命令语法仍然受到支持,但我们鼓励大家采用新的语法。

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

因此,首先

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

然后

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

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