Created
February 8, 2018 12:31
-
-
Save fernando-almeida/6598d262d534ae4633ae0048f77af677 to your computer and use it in GitHub Desktop.
Remove Docker container matching a given image name
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
#!/bin/bash | |
for docker_image_name in "$@" | |
do | |
container_ids=$(docker ps -a | awk '{ print $1,$2 }' | grep $docker_image_name | awk '{print $1 }') | |
if [ ! -z $container_ids ] | |
then | |
echo $container_ids | xargs -I {} docker rm -f {} | |
else | |
echo "No containers found for image \"$docker_image_name\"." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment