Can’t delete docker image with dependent child images

前端 未结 19 2118
挽巷
挽巷 2020-12-02 06:11

I am trying

docker rmi c565603bc87f

Error:

Error response from daemon: conflict: unable to delete c565603bc87f (ca

相关标签:
19条回答
  • 2020-12-02 06:56

    find the image id and parent id for all image created after the image in question with the following:

    docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=<image_id> -q)
    

    Then you call command:

    docker rmi {sub_image_id} 
    

    "sub_image_id" is ID of dependent image

    0 讨论(0)
  • 2020-12-02 06:57

    What worked to me was to use the REPOSITORY:TAG combination rather than IMAGE ID.

    When I tried to delete a docker image with the command docker rmi <IMAGE ID> with no containers associated with this image I had the message:

    $ docker rmi 3f66bec2c6bf
    Error response from daemon: conflict: unable to delete 3f66bec2c6bf (cannot be forced) - image has dependent child images
    

    I could delete with success when I used the command docker rmi RPOSITORY:TAG

    $ docker rmi ubuntu:18.04v1
    Untagged: ubuntu:18.04v1
    
    0 讨论(0)
  • 2020-12-02 06:57
    docker rmi <rep:tag>
    

    Ex:

    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    python              3.6            60f85556d5d2        4 days ago          174MB
    

    docker rmi python:3.6

    0 讨论(0)
  • 2020-12-02 06:58

    Building on Simon Brady's brute force method here, if you don't have a ton of images you can use this shell function:

    recursive_remove_image() {
      for image in $(docker images --quiet --filter "since=${1}")
      do
        if [ $(docker history --quiet ${image} | grep ${1}) ]
        then
          recursive_remove_image "${image}"
        fi
      done
      echo "Removing: ${1}"
      docker rmi -f ${1}
    }
    

    and then call it using recursive_remove_image <image-id>.

    0 讨论(0)
  • 2020-12-02 06:59
    # docker rm $(docker ps -aq)
    

    After that use the command as Nguyen suggested.

    0 讨论(0)
  • 2020-12-02 06:59

    Expanding on the answer provided by @Nguyen - this function can be added to your .bashrc etc and then called from the commandline to help clean up any image has dependent child images errors...

    You can run the function as yourself, and if a docker ps fails, then it will run the docker command with sudo and prompt you for your password.

    Does NOT delete images for any running containers!

    docker_rmi_dependants ()                                                                                                                                                         
    { 
      DOCKER=docker
      [ docker ps >/dev/null 2>&1 ] || DOCKER="sudo docker"
    
      echo "Docker: ${DOCKER}"
    
      for n in $(${DOCKER} images | awk '$2 == "<none>" {print $3}');
      do  
        echo "ImageID: $n";
        ${DOCKER} inspect --format='{{.Id}} {{.Parent}}' $(${DOCKER} images --filter since=$n -q);
      done;
    
      ${DOCKER} rmi $(${DOCKER} images | awk '$2 == "<none>" {print $3}')
    }
    

    I also have this in my .bashrc file...

    docker_rm_dangling ()  
    { 
      DOCKER=docker
      [ docker ps >/dev/null 2>&1 ] || DOCKER="sudo docker"
    
      echo "Docker: ${DOCKER}"
    
      ${DOCKER} images -f dangling=true 2>&1 > /dev/null && YES=$?;                                                                                                                  
      if [ $YES -eq 1 ]; then
        read -t 30 -p "Press ENTER to remove, or CTRL-C to quit.";
        ${DOCKER} rmi $(${DOCKER} images -f dangling=true -q);
      else
        echo "Nothing to do... all groovy!";
      fi  
    }
    

    Works with:

    $ docker --version 
    Docker version 17.05.0-ce, build 89658be
    
    0 讨论(0)
提交回复
热议问题