Skip to content

Instantly share code, notes, and snippets.

@christosavg
Last active January 31, 2020 09:14
Show Gist options
  • Save christosavg/b2012ebcabb1085cebd25beeb49823af to your computer and use it in GitHub Desktop.
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
#!/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