Getting real-time Docker events for containers
As we will be running many containers in production, it will be helpful if we can watch the real-time container events for monitoring and debugging purposes. Docker containers can report events such as create
, destroy
, die
, export
, kill
, oom
, pause
, restart
, start
, stop
, and unpause
. In this recipe, we will see how to enable event logging and then use filters to select specific event types, images, and containers.
Getting ready...
Make sure that the Docker daemon is running on the host and that you can connect through the Docker client.
How to do it...
Follow these steps:
- Start the Docker events logging with the following command:
$ docker events
- From the other terminal, do some container/image-related operations and you will see a result similar to the following screenshot on the first terminal:

After the events collection started, I created a container to just write a message to the console. As we can see from the preceding screenshot, a...