Skip to content

Instantly share code, notes, and snippets.

@dnephin
Last active October 21, 2022 20:44
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dnephin/c56b479810f863527e90 to your computer and use it in GitHub Desktop.
Save dnephin/c56b479810f863527e90 to your computer and use it in GitHub Desktop.
Execute a hook in './hooks/<service>/<action>' when that event is received
#!/bin/bash
set -e
function handle_event() {
local entry="$1"
local action=$(echo $entry | jq -r '.action')
local service=$(echo $entry | jq -r '.service')
local hook="./hooks/$service/$action"
if [ -x "$hook" ]; then
"$hook" "$entry"
fi
}
docker-compose events --json | (
while read line; do
handle_event "$line"
done
)
@urig-develeap
Copy link

This is lovely. Thank you :)

I think it would be great if this example could be included in the docker-compose documentation page for the events command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment