Docker Events

In this guide, we will see how to check the events in a docker daemon.

Suppose, We have a three nodes swarm cluster -

root@master:~# docker node ls
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
buc72h0hyo66gcilq7melh9pq *   master     Ready     Active         Leader           20.10.11
xvdyauu8t83r3udrqh6c5w8a8     worker01   Ready     Active                          20.10.11
xctiaq0n14aew1falekqybq53     worker02   Ready     Active                          20.10.11
root@master:~#

Now lets us ssh into all the nodes will trigger below command on the master node-

root@master:~# docker service create -d --secret dbpass alpine ping 8.8.8.8
mo8kp85oteuimjricutticxp6
root@master:~#

As soon as you run the above command, it will generate an event on the master node itself for the creation of service-

now run docker events on all nodes and perform some active on your docker engine you can see the logs below.

Also on other nodes terminal, you will find events as -

root@worker01:~# docker events
2021-11-22T04:29:38.658174177Z container create ae91b58f6a9152c8ab0f45ec07e3dd02cdaa83d8d80e6fceec5914078af5dd89 (com.docker.swarm.node.id=xvdyauu8t83r3udrqh6c5w8a8, com.docker.swarm.service.id=qg483id110in8b1rvltaf1844, com.docker.swarm.service.name=priceless_bose, com.docker.swarm.task=, com.docker.swarm.task.id=ipf789ue3q2du2h05mao14yj9, com.docker.swarm.task.name=priceless_bose.1.ipf789ue3q2du2h05mao14yj9, image=alpine:latest@sha256:635f0aa53d99017b38d1a0aa5b2082f7812b03e3cdb299103fe77b5c8a07f1d2, name=priceless_bose.1.ipf789ue3q2du2h05mao14yj9)
2021-11-22T04:29:38.698870147Z network connect db6da8624cab3e095642fd5acb1e9abb7a18c443223aceff474e589067ace920 (container=ae91b58f6a9152c8ab0f45ec07e3dd02cdaa83d8d80e6fceec5914078af5dd89, name=bridge, type=bridge)
2021-11-22T04:29:39.018051628Z container start ae91b58f6a9152c8ab0f45ec07e3dd02cdaa83d8d80e6fceec5914078af5dd89 (com.docker.swarm.node.id=xvdyauu8t83r3udrqh6c5w8a8, com.docker.swarm.service.id=qg483id110in8b1rvltaf1844, com.docker.swarm.service.name=priceless_bose, com.docker.swarm.task=, com.docker.swarm.task.id=ipf789ue3q2du2h05mao14yj9, com.docker.swarm.task.name=priceless_bose.1.ipf789ue3q2du2h05mao14yj9, image=alpine:latest@sha256:635f0aa53d99017b38d1a0aa5b2082f7812b03e3cdb299103fe77b5c8a07f1d2, name=priceless_bose.1.ipf789ue3q2du2h05mao14yj9)

Setting filter with the events

You can set filters along with the event's output to get specific output. For example-

docker events --filter 'event=create’

There are various filter options available. Only the last 1000 log events are returned. You can use filters to further limit the number of events returned.

Likewise, we can filter other values as well.