How does one remove an image in Docker?

I'm running Docker under Vagrant under OS X 10.8.4 (Mountain Lion), and whenever I try to delete a saved image, I get an error:

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

According to the rmi help, the proper syntax is docker rmi IMAGE [IMAGE...] , and I'm not sure what to make of that.

How can I delete an image?

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

$docker info
Containers: 1
Images: 3

Interestingly, when I run docker ps , no containers show up at all. Running docker images shows four (4) base images and one (1) node image.


Try docker rmi node . That should work.

Seeing all created containers is as simple as docker ps -a .

To remove all existing containers (not images!) run docker rm $(docker ps -aq)


The following are some of the ways to remove docker images/containers:

Remove single image

docker rmi image_name:version/image-id

Remove all images

docker rmi $(docker images -qf "dangling=true")

Kill containers and remove them:

docker rm $(docker kill $(docker ps -aq))

Note: Replace kill with stop for graceful shutdown

Remove all images except "my-image"

Use grep to remove all except my-image and ubuntu

docker rmi $(docker images | grep -v 'ubuntu|my-image' | awk {'print $3'})

Or (without awk)

docker rmi $(docker images --quiet | grep -v $(docker images --quiet ubuntu:my-image))


Delete all docker containers

docker rm $(docker ps -a -q)

Delete all docker images

docker rmi $(docker images -q)
链接地址: http://www.djcxy.com/p/3004.html

上一篇: 如何处理docker中的永久存储(例如数据库)

下一篇: 如何在Docker中移除图像?