Remove docker image which has dependent children images

I want remove docker images, but I meet error message like this:

Error response from daemon: conflict: unable to delete 47bcc53f74dc
(cannot be forced) – image has dependent child images

  • Is this correct way to deploy springboot cloud netflix in production on multi host network?
  • Docker: can't run hello-world. Windows 10
  • error with docker container with postgresql
  • Performing a npm install via Docker on a windows host
  • JVM cant map reserved memory when running in Docker container
  • I can't locate my host directory, which I attached to Docker
  • I stop all containers by docker stop $(docker ps -a -q) command. After that, I remove all busybox images by docker rmi $(docker images | grep "busybox" | awk '{print $3}') command. And I meet error message like above.

    I show docker images | grep busybox and get information like below:

    busybox             1                   47bcc53f74dc        6 months ago        1.113 MB
    busybox             1-uclibc            47bcc53f74dc        6 months ago        1.113 MB
    busybox             1.24                47bcc53f74dc        6 months ago        1.113 MB
    busybox             1.24-uclibc         47bcc53f74dc        6 months ago        1.113 MB
    busybox             1.24.2              47bcc53f74dc        6 months ago        1.113 MB
    busybox             1.24.2-uclibc       47bcc53f74dc        6 months ago        1.113 MB
    busybox             uclibc              47bcc53f74dc        6 months ago        1.113 MB
    

    How can I remove busybox images? Thanks for any advices.

  • NoClassDefFoundError in Tomcat for Abstract Class
  • What are Docker image “layers”?
  • Kubernetes and Dockerfile
  • Using the RUN instruction in a Dockerfile with 'source' does not work
  • Kubernetes can't start due to too many open files in system
  • How to keep docker containers running when they are installed with ansible
  • One Solution collect form web for “Remove docker image which has dependent children images”

    The warning suggests you that some of the containers still linked (inherit) docker FS layers of ones you’re going to delete. There is no option to delete intermediate docker filesystem layers without recreating child images based on those.

    Say, you’ve got configuration like:

    base_layer_A -> base_layer_B
               \        \_ child_layer_D
                \__ container C
    

    … willing to delete container C and layer A.

    You cannot do so (because layer B is based on layer A). That’s the most likely reason of your problem

    PS: docker images -a might shed some light to you (unlikely). There was a ‘-tree’ switch once to help with such case, but it’s gone now, unfortunately


    Here is a straight and brute way to clean up abandoned docker containers and deprecated image layers

    #!/usr/bin/env bash
    set -euo pipefail
    
    for c in $(docker ps -a -f status=exited -f status=created -f status=dead --format="{{.ID}}"); do
        docker rm $c
    done
    for img in $(docker images -f dangling=true --format="{{.ID}}"); do
        docker rmi $img
    done
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.