Skip to content

Instantly share code, notes, and snippets.

@RSheremeta
Created August 21, 2023 09:36
Show Gist options
  • Save RSheremeta/b60a1112de91e5aa6ab2518207497847 to your computer and use it in GitHub Desktop.
Save RSheremeta/b60a1112de91e5aa6ab2518207497847 to your computer and use it in GitHub Desktop.
a script for doing an annoying job - removing unused docker containers
# ! /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..."
@RSheremeta
Copy link
Author

Apparently, I recently realized that the docker run cmd could be used with --rm flag which removes the container once it gets stopped.
So this script is useless :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment