Created
August 21, 2023 09:36
-
-
Save RSheremeta/b60a1112de91e5aa6ab2518207497847 to your computer and use it in GitHub Desktop.
a script for doing an annoying job - removing unused docker containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ! /bin/bash | |
| if [ $# -eq 0 ] | |
| then | |
| echo "the docker target is not provided, aborting..." | |
| exit 1 | |
| fi | |
| target=$1 | |
| echo "starting looking up for docker containers of target $target" | |
| containers_found=$(docker ps -a | grep $target | grep Exited | awk '{print $1}') | |
| for container_id in $containers_found | |
| do | |
| docker rm $container_id | |
| done | |
| echo "no docker containers need to remove, stopping..." |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently, I recently realized that the
docker runcmd could be used with--rmflag which removes the container once it gets stopped.So this script is useless :))