Logging A Docker Environment With Portainer (Or Not)
One of the reasons it’s so challenging to log Docker environments is their multi-layered nature. Portainer allows you to easily access three main data streams.
Join the DZone community and get the full member experience.Join For Free
for the sake of our dedicated readers, let’s start with the conclusion: portainer is not a logging solution for docker.
but wait! before you move on — portainer is an extremely useful and easy-to-use ui for docker that is well worth exploring if docker is part of your day-to-day work, and it’s open-source!
still with me? great!
so, what is portainer? simply put, it’s a ui for docker that allows you to “easily manage your docker hosts or swarm clusters.” in other words, it’s a pretty face on top of the docker api.
portainer runs as a lightweight (9.132 mb) container that can run on any docker engine (mac, linux, and windows) and can be used to manage images, containers, volumes, networks and, yes, logs.
below are my notes.
setting it up
installing portainer is easy and can be done with two simple commands.
start by pulling the image from the docker hub:
docker pull portainer/portainer
next, we need to run the container. since it needs access to the docker daemon on our host, we need to mount the socket file from within the container host:
docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
now that your container is running, all that’s left to do is open your browser with the following url:
you now need to go through some simple configuration steps.
you should be seeing the password configuration page, where all you need to do is enter and then confirm a password.
clicking validate , you will be asked to enter your password one last time. then, an additional configuration page is displayed asking you which docker host you want to manage with portainer. you can choose between a remote docker host and a local docker.
once you complete that simple task, click connect and you will have access to portainer!
the default page that opens up is a dashboard. the dashboard gives you an overview of your docker node (or nodes in case of swarm) as well as the number and status of your containers, the number and total size of images, the number of volumes, and the number of existing networks.
if you’re looking for general information on the docker engine, select the docker tab from the menu on the left.
using the same menu, you can manage the main building blocks comprising any docker environment: containers, images, networks, and volumes.
for example, selecting images gives you a list of all the images pulled. you can see their id, tag, total size, and the date that they were created.
the great thing about portainer is that it allows you not only to get an overview of the environment but also to manage it. for example, if you want to pull a new image (from the docker hub or a different registry) or remove an existing image, you can do so from this page.
on the containers page, you will be able to see a list of all your containers. selecting a container will give you all the details about the selected container including its status, network, and port configuration as well as the option to build an image from the container. you can even open a terminal with bash into the container.
an interesting feature is the ability to run new containers based on ready-made portainer templates. select app templates from the menu, choose which template to use, configure the container name and port mapping, and create (or run) your container.
from a logging perspective, portainer gives visibility into resources that would otherwise be harder to access.
as explained in this post, one of the reasons it’s so challenging to log docker environments is their multi-layered nature. there are various metrics and logs to measure such as the stdout and stderr output of a container, docker container statistics, and docker daemon events.
while portainer does not offer a way to get a comprehensive and centralized view of these three types, it does allow you to easily access the three data streams.
to see container logs, for example, you need to select one of the containers on the containers page and then click logs . as you can see below, you get a nice view of the stdout and stderr output:
the same goes for docker stats. it’s worth noting that the data is refreshed upon page load, so there is no data retention:
docker events (docker daemon “admin” actions such as kill, attach, restart, and die) can be viewed on the events page.
summing it up
portainer fills in an empty void in the docker world by wrapping up the docker api with a pretty, intuitive, and easy-to-use ui.
from a logging perspective, though, there is much that is missing such as the very basic ability to query the logs to the more advanced function of visualizing them and being able to build a comprehensive monitoring dashboard.
but that’s ok. portainer does not claim to be a logging solution for docker, and it is excellent at what it does claim to be — “an open-source, lightweight management ui which allows you to easily manage your docker host or swarm cluster.”
as such, it’s well worth checking out.
Published at DZone with permission of Daniel Berman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.