13

I am trying to delete a test image:

docker image rm test-image

but I'm getting

Error response from daemon: conflict: unable to remove repository reference "test-image" (must force) - container 4ca6d09c1103 is using its referenced image 133c9587889f

However, this container does not exist:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
fff756b1399a        rocker/shiny        "/usr/bin/shiny-se..."   6 months ago        Up 12 days          0.0.0.0:3838->3838/tcp   shinyServerBdl2

So: What is this about?

I've called

docker build . -t test-image
docker run -it test-image

to create the image from a Dockerfile but why can't I delete the image here? I also tried

docker rmi test-image

without success.

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • Possible duplicate of [Docker error cannot delete docker container, conflict: unable to remove repository reference](https://stackoverflow.com/questions/33907835/docker-error-cannot-delete-docker-container-conflict-unable-to-remove-reposito) – David R Feb 21 '18 at 15:57
  • Please reboot your system, it works for me after reboot (I was using UBUNTU as a host machine) – Rohan J Mohite Feb 21 '18 at 15:59
  • @RohanJMohite Unfortunately I cannot reboot this machine. – Stefan Falk Feb 21 '18 at 16:00

2 Answers2

23

Make sure that a container does not exist that is using the image. The container can be stopped and thus won't show when you run docker ps. You can do docker ps --all to view all runninn and stopped container. In short, running the following should remove the image:

docker container rm 4ca6d09c1103
docker image rm test-image
yamenk
  • 46,736
  • 10
  • 93
  • 87
2

If you are in dev environment, and if you want to remove all of images, you can use this:

$ docker rm $(docker ps -a -q) -f

But don't do this in prod!

lechat
  • 390
  • 2
  • 15