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

  • docker multi-host networking cluster-advertise option
  • how to split string to array and loop over it?
  • Docker: Expose a range of ports
  • How to claim free space generated by deleting docker images in Mac
  • Raspberry-pi docker error: standard_init_linux.go:178: exec user process caused “exec format error”
  • aufs au_opts_parse:1155:docker[2010] unknown option dirperm1
  • 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.

  • docker - connect over http to running container
  • Docker Maven plugin: how to specify shm size when running a container
  • How do i get Google Container Registry to accept my json credentials?
  • Can't install supervisor on a Docker container ubuntu:trusty
  • Docker Tooling for Eclipse - how to connect to docker daemon running inside VM
  • Docker container with status “Dead” after consul healthcheck runs
  • 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.