GithubHelp home page GithubHelp logo

dmuth / docker-remove-dependent-child-images Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 3.0 214 KB

Script to remove dependent child images of a Docker Container

License: Apache License 2.0

Shell 99.65% Dockerfile 0.35%

docker-remove-dependent-child-images's Introduction

Update 21 May 2021: I learned a new trick which probably makes this script completely unnecessary--just running docker rmi $(docker images --filter "dangling=true" -q ) should do the trick. I will keep this script around for legacy reasons, though.

Script to remove dependent child images of a Docker Container

As much as I love using Docker, one of the frustrations I have is when I try to remove an an image which other images are based on, only to get this error:

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

I did some searches on Google, and most of the advice centered around the heavy-handed approach of removing all Docker images and basically starting over with a clean slate. That approach didn't set well with me because it doesn't strike me as all that efficient, and also causes me to have to spend more time waiting for unrelated containers to build.

That prompted me to write a script which, when provided with the ID of a container to remove, will recurse through all child containers and delete them first.

Quick and Dirty Usage

bash <(curl -s https://raw.githubusercontent.com/dmuth/docker-remove-dependent-child-images/master/docker-remove-image) IMAGE_ID

That will delete the image IMAGE_ID, and all child images.

No muss, no fuss, no awkward explanations to senior engineers.

Sample Output

Output of the run of demo.sh:

Development

  • Run the script ./tests.sh to create some nested containers and then run this script.

Contact

docker-remove-dependent-child-images's People

Contributors

dmuth avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

docker-remove-dependent-child-images's Issues

Does not identify child images

This code in the docker-remove-image script:

docker images --filter since=IMAGE_ID

Identifies images created more recently (newer) than the specified image (IMAGE_ID), not child images.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.