Docker error cannot delete docker container, conflict: unable to remove repository reference
There is a difference between docker images and docker containers. Check this SO Question.
In short, a container is a runnable instance of an image. which is why you cannot delete an image if there is a running container from that image. You just need to delete the container first.
docker ps -a # Lists containers (and tells you which images they are spun from)
docker images # Lists images
docker rm <container_id> # Removes a stopped container
docker rm -f <container_id> # Forces the removal of a running container (uses SIGKILL)
docker rmi <image_id> # Removes an image
# Will fail if there is a running instance of that image i.e. container
docker rmi -f <image_id> # Forces removal of image even if it is referenced in multiple repositories,
# i.e. same image id given multiple names/tags
# Will still fail if there is a docker container referencing image
Update for Docker 1.13+ [Since Jan 2017]
In Docker 1.13, we regrouped every command to sit under the logical object it’s interacting with
Basically, above commands could also be rewritten, more clearly, as:
docker container ls -a
docker image ls
docker container rm <container_id>
docker image rm <image_id>
Also, if you want to remove EVERYTHING you could use:
docker system prune -a
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all unused images
- all build cache
First, remove the container names
$ sudo docker rm backstabbing_ritchie
The result
$ sudo docker rm backstabbing_ritchie
backstabbing_ritchie
delete the second part, which is listed on the container to be deleted
$ sudo docker rm drunk_feynman
drunk_feynman
Second, remove the container
$ sudo docker rmi training/webapp
The result
$ sudo docker rmi training/webapp
Untagged: training/webapp:latest
Deleted: 54bb4e8718e8600d78a5d7c62208c2f13c8caf0e4fe73d2bc0e474e93659c0b5
Deleted: f74dd040041eb4c032d3025fe38ea85de8075992bdce6789b694a44b20feb8de
Deleted: 7cbae69141977b99c44dc6957b032ad50c1379124d62b7d7d05ab7329b42348e
Deleted: abb991a4ed5e4cde2d9964aec4cccbe0015ba9cc9838b696e7a32e1ddf4a49bd
Deleted: 1952e3bf3d7e8e6a9b1e23bd4142e3c42ff7f4b7925122189704323593fd54ac
Deleted: f95ebd363bf27a7546deced7a41a4099334e37a3d2901fa3817e62bb1ade183f
Deleted: 20dd0c75901396d41a7b64d551ff04952084cc3947e66c67bae35759c80da338
Deleted: 2505b734adda3720799dde5004302f5edb3f2a2ff71438f6488b530b728ba666
Deleted: 2ee0b8f351f753f78f1178000ae37616eb5bf241d4ef041b612d58e1fd2aefdc
Deleted: 2ce633e3e9c9bd9e8fe7ade5984d7656ec3fc3994f05a97d5490190ef95bce8d
Deleted: 98b15185dba7f85308eb0e21196956bba653cf142b36dc08059b3468a01bf35d
Deleted: 515565c29c940355ec886c992231c6019a6cffa17ff1d2abdfc844867c9080c5
Deleted: 2880a3395eded9b748c94d27767e1e202f8d7cb06f1e40e18d1b1c77687aef77
Check the continer
$ sudo docker ps -as
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
78479ffeba5c ubuntu "/bin/bash" 43 hours ago Exited (0) 43 hours ago sharp_wescoff 81 B (virtual 187.7 MB)