Skip to content

Instantly share code, notes, and snippets.

@earnubs
Created July 3, 2024 09:37
Show Gist options
  • Save earnubs/91ef1256d0083160f06b85b69fff64ef to your computer and use it in GitHub Desktop.
Save earnubs/91ef1256d0083160f06b85b69fff64ef to your computer and use it in GitHub Desktop.
Bash trap and cleanup Docker
#!/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