The Docker engine, when creating, running, stopping, and removing containers and other resources such as volumes or networks, produces a log of events. These events can be consumed by external systems, such as some infrastructure services that use them to make informed decisions. An example of such a service could be a tool that creates an inventory of all containers that are currently running on the system.
We can hook ourselves into this stream of system events and output them, for example in a terminal, by using the following command:
$ docker system events
This command is a blocking command. Thus, when you execute it in your terminal session the according session is blocked. Therefore, we recommend that you always open an extra window when you want to use this command.
Assuming we have executed the preceding command in an extra terminal window, we can now test it and run a container like this:
$ docker container run --rm alpine echo "Hello World"
The output produced...