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

  • Execute a Firefox Browser in a Docker Container for Selenium testing
  • docker-compose build error: command 'gcc' failed with exit status 4
  • Running HHVM's “hh_server” tool inside Docker container fails
  • docker backup on production DB
  • How to join ElasticSearch cluster with nodes in docker instance
  • Connection refused by Docker container
  • 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.

  • Why php-fpm from official Docker image doesn't work for me?
  • Docker container write permissions
  • Docker cannot mount volume over existing file
  • Curl do Docker Container on same Docker Host (nginx-proxy)
  • Cannot read docker container logs: Permission denied
  • is it possible to Get value from .env file when building image via dockerFile
  • 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.