5

I am trying to hook on to docker event bus to listen to various events happening on the swarm such as nodes leaving and joining the cluster, services that are created etc. Questions.

  1. Is it possible to get such info at swarm level ?.

  2. If so, Does dockerpy library be used to listen to such events?

Alejandro Galera
  • 3,445
  • 3
  • 24
  • 42
B_B
  • 2,013
  • 3
  • 14
  • 13

2 Answers2

2

From the docker API documentation: https://docs.docker.com/engine/api/v1.39

Various objects within Docker report events when something happens to them.

Containers report these events: attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, exec_die, export, health_status, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, and update

Services report these events: create, update, and remove

Nodes report these events: create, update, and remove

And from dockerpy documentation: https://docker-py.readthedocs.io/en/stable/api.html?highlight=event

events(since=None, until=None, filters=None, decode=None) Get real-time events from the server. Similar to the docker events command.

Parameters: since (UTC datetime or int) – Get events from this point until (UTC datetime or int) – Get events until this point filters (dict) – Filter the events by event time, container or image decode (bool) – If set to true, stream will be decoded into dicts on the fly. False by default. Returns: A docker.types.daemon.CancellableStream generator

Raises: docker.errors.APIError – If the server returns an error.

vimal-k
  • 293
  • 3
  • 7
0

Base on Docker official documentation https://docs.docker.com/engine/reference/commandline/events/ you can use:

docker events --filter 'scope=swarm'

And if you want to use it in dockerpy you can use:

import docker

client = docker.APIClient()

for event in client.events(decode=True, filters={"scope":"swarm"}):
   print(event)
ikandars
  • 486
  • 5
  • 5