DEV Community

Cover image for View your Docker Container Logs with Netdata
Andrej Friesen
Andrej Friesen

Posted on • Originally published at ajfriesen.com on

View your Docker Container Logs with Netdata

View your Docker Container Logs with Netdata

Hey nerds 🤓

just a quick tip here. I am a big Netdata fan because it is a no-setup but full out of the box monitoring solution. I am not sure when, but Netdata also allows you to check your journald logs in their dashboard.

No need for other software or to log into your machine, you can also just look at those logs via your browser anywhere you want.

But what about docker logs?

That is actually super easy. You just have to change your docker log driver to journald:

{
  "log-driver": "journald"
}
Enter fullscreen mode Exit fullscreen mode

You need to restart docker for the change to take effect:

sudo systemctl restart docker
Enter fullscreen mode Exit fullscreen mode

Now, your already-running containers will still have the old logging driver. You can check this with:

docker inspect --format='{{.HostConfig.LogConfig.Type}}' caddy
json-file
Enter fullscreen mode Exit fullscreen mode

You have to recreate the containers in order to change the log driver. With docker compose it's just a:

docker compose up -d --force-recreate
Enter fullscreen mode Exit fullscreen mode

Now the log driver should be journald.

Checking logs

You can still run docker logs webserver but also journalctl CONTAINER_NAME=webserver . But I do not see a benefit to use journalctl instead of docker logs.

However, now you will have the field CONTAINER_NAME available in the Netdata log section and can check the container logs there:

View your Docker Container Logs with Netdata

View your Docker Container Logs with Netdata

Filtering Docker Logs in Netdata with CONTAINER_NAME, in this case: syncthing

Now you can check your logs on the go without needing to log in.

Benefits

Another benefit of using the journald log driver is, that we have one tool which takes care of logs. Before Docker will take of Docker logs and systemd will take care of everything else. The problem is, that Docker logs can fill up the disk pretty quickly.

Now with journald we have one tool to take of logs and by default systemd will only write a maximum of 4GB logs to your disk. There is no way Docker logs will fill up the disk.

There are a bunch of configuration options for journald log size. Here are a few examples if you want to edit them to your use case:

SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=, SystemMaxFiles=, RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize=, RuntimeMaxFiles=¶

Enter fullscreen mode Exit fullscreen mode

You can read more here about journald config: https://www.freedesktop.org/software/systemd/man/latest/journald.conf.html

And here for reference the Docker log driver docs: https://docs.docker.com/config/containers/logging/journald/

Have a great day! 👋

Top comments (0)