Skip to content

Instantly share code, notes, and snippets.

@lawrenceching
Created March 27, 2021 16:28
Show Gist options
  • Save lawrenceching/fbb9fa26202037617b37f3d736fb1358 to your computer and use it in GitHub Desktop.
Save lawrenceching/fbb9fa26202037617b37f3d736fb1358 to your computer and use it in GitHub Desktop.
Delete all exited containers
#!/bin/bash
containerIds=( $(docker container ls --all | grep Exited | cut -d ' ' -f 1) )
length="${#distro[@]}"
if [ "0" = "$length" ]; then
echo "No exited container"
exit 0
fi
for id in "${containerIds[@]}"
do
docker rm $id
echo "Deleted $id"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment