Skip to content

Instantly share code, notes, and snippets.

@Mualig
Created January 4, 2022 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mualig/fb6632da53831bdfd110d43acea3a892 to your computer and use it in GitHub Desktop.
Save Mualig/fb6632da53831bdfd110d43acea3a892 to your computer and use it in GitHub Desktop.
Kill / Clear Docker's containers stuck in "Created" state
#!/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