There is a difference between docker images and docker containers. Check this SO Question.
In short, a container is a running 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 container
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
网友评论