Created
July 3, 2024 09:37
-
-
Save earnubs/91ef1256d0083160f06b85b69fff64ef to your computer and use it in GitHub Desktop.
Bash trap and cleanup Docker
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
#!/usr/bin/env bash | |
set -xeuo pipefail | |
# Docker use is only as an example, this is just to demonstrate cleanup | |
function cleanup() | |
{ | |
echo "Removing containers..." | |
docker rm -f echo | |
} | |
trap cleanup EXIT | |
docker run -d --name echo -p 3123:80 ealen/echo-server:0.9.2 | |
sleep 1s | |
test $(curl -s -o /dev/null --write-out "%{http_code}" http://localhost:3123) -eq 200 | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment