Monitoring Docker containers
If you extend this tutorial and develop fully featured websites in your containers, then you’ll want to keep an eye on how much resources each container is using. You could do this by logging into each container and parsing output from ps or other traditional commands, but that seems painful. You could also modify the image to include Munin or Awstats, which would give access to all kinds of information via a web page. But it’s nice to keep our containers simple. Running a Munin node, say, would require setting up an RRD database, and generating a lot of data, which inside the container could cause more problems than it solves.
You can get some rudimentary statistics with a simple: $ docker stats
This will show you CPU, memory, network I/O and block device I/O for each container, which is enough to get a rough handle on what’s agwarn and see if anything needs remedying.
There are also countless projects for more in-depth monitoring. One such is the excellent
sen from Red Hat’s Tomas Tomecek. It’s available as (you’ve guessed it) a docker image that you can run from your host as follows: $ sudo docker run -v /var/run/docker.sock:/run/ docker.sock -ti -e TERM tomastomecek/sen
The initial screen shows the status of any containers currently running (including the
sen container itself, whoa) and you can select one of them using the cursor keys and Enter to find out more specifics and view some nice ASCII graphs. It’s an awesome tool, and you should read more about it at https://github. com/TomasTomecek/sen. Finally, we couldn’t do this without mentioning the wonderful (though possibly impractical) Dockercraft, which enables you to control containers from the comfort of Minecraft. Find out more at https://github. com/docker/dockercraft.