imagedockercontainers

Unable to delete docker image of a running container using -f option


I tried to create a container using the following

docker run -it centos bash

and exited without killing it.

Now I'm trying to delete the centos image using its image ID.

docker rmi -f 0f3e07c0138f
Error response from daemon: conflict: unable to delete 0f3e07c0138f (cannot be forced) - image is being used by running container a9eab034a426

On docker documentation page, it says " You cannot remove an image of a running container unless you use the -f option." but still I'm unable to remove image using -f. What can be the explanation for this? Should there a correction in documentation?


Solution

  • See these results

    $ sudo docker rmi centos
    Error response from daemon: conflict: unable to remove repository reference 
    "centos" (must force) - container be8f69d76892 is using its referenced image 
    0f3e07c0138f
    $ sudo docker rmi -f 0f3e07c0138f
    Error response from daemon: conflict: unable to delete 0f3e07c0138f (cannot be 
    forced) - image is being used by running container be8f69d76892
    $ sudo docker rmi -f centos
    Untagged: centos:latest
    Untagged: 
    centos@sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
    

    docker rmi -f option only works on image name if container is running, even then it just untag the image but the image remains there with "none" repo and tag. see

    <none>   <none>       0f3e07c0138f        3 months ago        220MB
    

    And when you will run

    sudo docker ps
    

    you will see that image id is there instead of the image name

    CONTAINER ID        IMAGE                                                
    be8f69d76892        0f3e07c0138f
    

    I have removed other info in this docker ps command's result.