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


当前回答

为什么没有人提到码头工人作曲!我刚用了一个星期,没有它我无法生存。你只需要写一个只需要几分钟学习的yml,然后你就可以开始了。它可以引导映像、容器(在所谓的服务中需要),并让您像使用docker本地命令一样查看日志。试试看:

docker-compose up -d
docker-compose down --rmi 'local'

在使用docker compose之前,我编写了自己的shell脚本,然后我必须在需要时定制脚本,尤其是在应用程序架构发生变化时。现在我不必再这样了,多亏了docker compose。

其他回答

图像:

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

容器:

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

使用删除所有文件

步骤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图像

用于删除单个图像

使用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 rm容器名称

docker rmi映像名称

码头工人帮助rm删除一个或多个容器rmi删除一个或多个图像