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

  • Privileges in an Ubuntu Docker container after USER statement in Dockerfile
  • I can not access my Container Docker Image by HTTP
  • Is it possible to shut down the host machine by executing a command on one of its docker container?
  • Is it possible for image to have multiple tags?
  • Can I use docker to run MSBuild on OSX?
  • How to Keep Docker Container Running After Starting Services?
  • 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.

  • Fail to set ulimit inside docker container
  • EC2 User Data runs script but does not boot up application
  • How can my docker harddrive be bigger than the hosts?
  • Can't connect to MySQL container on AWS ECS
  • Accessing host machine as localhost from a Docker container that's also inside a boot2docker vm
  • 502 Bad Gateway error using Docker-Compose and nginx-proxy
  • 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.