Last active
January 31, 2020 09:14
-
-
Save christosavg/b2012ebcabb1085cebd25beeb49823af to your computer and use it in GitHub Desktop.
Fast and easy way to stop and remove a Docker container as well as its leftovers using BASH
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 | |
container_name=YOUR_CONTAINER_NAME | |
if [[ ! -z $(docker ps | grep $container_name) ]] | |
then | |
echo found $container_name container | |
sudo docker kill $(docker ps | grep $container_name| cut -f 1 -d " "); | |
echo killed $container_name container | |
else | |
echo $container_name is not running | |
fi | |
echo searching for container leftovers | |
if [[ ! -z $(sudo docker ps -a | grep $container_name) ]] | |
then | |
echo container leftovers found | |
sudo docker rm $(sudo docker ps -a | grep $container_name | cut -f 1 -d " "); | |
echo leftovers flushed | |
fi | |
echo all is clean | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment