In this recipe, we will learn to monitor Docker containers.
Docker provides inbuilt monitoring with the docker stats
command, which can be used to get a live stream of the resource utilization of Docker containers.
To monitor multiple containers at once using their respective IDs or names, use this command:
$ docker stats mysql f9617f4b716c
With
docker logs
, you can fetch logs of your application running inside a container. This can be used similarly to thetail -f
command:$ docker logs -f ubuntu
Docker also records state change events from containers. These events include start, stop, create, kill, and so on. You can get real-time events with
docker events
:$ docker events
To get past events, use the
--since
flag withdocker events
:$ docker events --since '2015-11-01'
You can also check the changes in the container filesystem with the
docker...