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! πŸ‘‹

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo πŸ“Šβœ¨

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay