Skip to content

Instantly share code, notes, and snippets.

@sgpinkus
Created May 1, 2022 03:22
Show Gist options
  • Save sgpinkus/45f6c2728bcfb36bda29b83910fac769 to your computer and use it in GitHub Desktop.
Save sgpinkus/45f6c2728bcfb36bda29b83910fac769 to your computer and use it in GitHub Desktop.
[Unit]
Description=service that simply pipes certain docker events to logs
[Service]
ExecStart=/usr/local/bin/docker-events-to-logs.sh
Restart=on-failure
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#!/bin/bash
# docker events --filter="type=container" --filter="type=service" --filter="type=node" --format '{{json .}}' | jq '.'
docker events \
--filter 'type=container' \
--filter 'type=service' \
--format 'type={{.Type}} action="{{.Action}}" scope={{.Scope}} exit_code="{{.Actor.Attributes.exitCode}}" container_name={{.Actor.Attributes.name}} image={{.Actor.Attributes.image}} swarm_stack="{{index .Actor.Attributes "com.docker.stack.namespace"}}" swarm_service="{{index .Actor.Attributes "com.docker.stack.namespace"}}"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment