Created
January 4, 2022 15:26
-
-
Save Mualig/fb6632da53831bdfd110d43acea3a892 to your computer and use it in GitHub Desktop.
Kill / Clear Docker's containers stuck in "Created" state
This file contains 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
#!/usr/bin/env sh | |
# Get the list of all containers | |
containers=$(docker ps -a | grep "Created" | awk '{print $1}') | |
# Get length of the list | |
length=$(echo "$containers" | awk '{print NF}') | |
echo "Gonna kill ${length} containers" | |
# Kill the stuck containers | |
for container in $containers; do | |
echo "Killing container $container" | |
ps aux | grep "${container}" | awk '{print $2}' | xargs kill -9 | |
docker rm "${container}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment