Skip to content

Instantly share code, notes, and snippets.

@BaksiLi
Last active August 10, 2023 06:45
Show Gist options
  • Save BaksiLi/f86f760baae2ed4a6459624b8bbda4c2 to your computer and use it in GitHub Desktop.
Save BaksiLi/f86f760baae2ed4a6459624b8bbda4c2 to your computer and use it in GitHub Desktop.
Docker command to kill and remove a container with its image
alias undock='f() {
if sudo docker kill $1; then
echo "[+] Successfully killed: $1"
else
echo "[-] Failed to kill: $1"
fi
if sudo docker rm $1; then
echo "[+] Successfully removed: $1"
else
echo "[-] Failed to remove: $1"
fi
unset -f f
}; f'
# One-line version
# alias undock='f() { sudo docker kill $1 && echo "[+] Successfully killed: $1" || echo "[-] Failed to kill: $1"; sudo docker rm $1 && echo "[+] Successfully removed: $1" || echo "[-] Failed to remove: $1"; unset -f f; }; f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment