https://github.com/dmuth/docker-remove-dependent-child-images
Script to remove dependent child images of a Docker Container
https://github.com/dmuth/docker-remove-dependent-child-images
Last synced: 10 months ago
JSON representation
Script to remove dependent child images of a Docker Container
- Host: GitHub
- URL: https://github.com/dmuth/docker-remove-dependent-child-images
- Owner: dmuth
- License: apache-2.0
- Created: 2019-11-17T22:55:36.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2021-05-22T02:44:31.000Z (about 5 years ago)
- Last Synced: 2025-04-12T14:51:30.315Z (about 1 year ago)
- Language: Shell
- Size: 209 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
**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
- Email: doug.muth AT gmail DOT com
- @dmuth on Twitter
- Facebook
- Blog