How does one remove a Docker image?

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)

To remove an image from Docker using the image ID:

  1. Get the list of all Images

    docker images
    
  2. Identify the image ID of the image you want to delete, for example:

    REPOSITORY     TAG     IMAGE ID        CREATED        VIRTUAL SIZE
    kweku360/java  latest  08d3a9b8e166    2 weeks ago         5.733 GB`
    
  3. Finally remove the image using the image ID (only the first three digits are required)

    docker rmi 08d