Not being able to remove docker images with "docker image prune -a"

Viewed 496

I have two docker images that I would like to remove, but it seems that they cannot be removed with docker image prune -a. Why? The two images are not used in the terminal, since I just restarted the terminal.

(base) ~ % docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
test_docker         latest              245e34778213        10 minutes ago      1.34GB
<none>              <none>              02f2aa7b08bb        41 minutes ago      1.21GB
(base) ~ % docker image prune -a
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

How can I remove the images?

2 Answers

You'll need to make sure all Docker containers are stopped and removed, after that you can remove the Docker images.

Stop and remove all docker containers and images:

  1. List all containers (only IDs) docker ps -aq.
  2. Stop all running containers. docker stop $(docker ps -aq)
  3. Remove all containers. docker rm $(docker ps -aq)
  4. Remove all images. docker rmi $(docker images -q) or docker image prune -a

docker image prune only remove images not currently associated with a container.

You may want to use docker rmi [image id] (example docker rmi 245e34778213) instead.

Related