<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrej Friesen</title>
    <description>The latest articles on DEV Community by Andrej Friesen (@ajfriesen).</description>
    <link>https://dev.to/ajfriesen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F481756%2F834662fe-dc91-4b32-98d0-a06397ccb074.jpeg</url>
      <title>DEV Community: Andrej Friesen</title>
      <link>https://dev.to/ajfriesen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ajfriesen"/>
    <language>en</language>
    <item>
      <title>View your Docker Container Logs with Netdata</title>
      <dc:creator>Andrej Friesen</dc:creator>
      <pubDate>Thu, 20 Jun 2024 20:24:53 +0000</pubDate>
      <link>https://dev.to/ajfriesen/view-your-docker-container-logs-with-netdata-4lk5</link>
      <guid>https://dev.to/ajfriesen/view-your-docker-container-logs-with-netdata-4lk5</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16m4eiy75i8l8hzzyu0j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16m4eiy75i8l8hzzyu0j.png" alt="View your Docker Container Logs with Netdata" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hey nerds 🤓&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;journald&lt;/code&gt; logs in their dashboard.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  But what about docker logs?
&lt;/h2&gt;

&lt;p&gt;That is actually super easy. You just have to change your docker log driver to &lt;code&gt;journald&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "log-driver": "journald"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need to restart docker for the change to take effect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, your already-running containers will still have the old logging driver. You can check this with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker inspect --format='{{.HostConfig.LogConfig.Type}}' caddy
json-file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have to recreate the containers in order to change the log driver. With &lt;code&gt;docker compose&lt;/code&gt; it's just a:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker compose up -d --force-recreate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the log driver should be &lt;code&gt;journald&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking logs
&lt;/h2&gt;

&lt;p&gt;You can still run &lt;code&gt;docker logs webserver&lt;/code&gt; but also &lt;code&gt;journalctl CONTAINER_NAME=webserver&lt;/code&gt; . But I do not see a benefit to use &lt;code&gt;journalctl&lt;/code&gt; instead of &lt;code&gt;docker logs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, now you will have the field &lt;code&gt;CONTAINER_NAME&lt;/code&gt; available in the Netdata log section and can check the container logs there:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqiemc49oblg2tmdkalx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqiemc49oblg2tmdkalx.png" alt="View your Docker Container Logs with Netdata" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzdqcjevj721wtd7jsi93.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzdqcjevj721wtd7jsi93.png" alt="View your Docker Container Logs with Netdata" width="528" height="934"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Filtering Docker Logs in Netdata with CONTAINER_NAME, in this case: syncthing&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now you can check your logs on the go without needing to log in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;Another benefit of using the &lt;code&gt;journald&lt;/code&gt; log driver is, that we have one tool which takes care of logs. Before Docker will take of Docker logs and &lt;code&gt;systemd&lt;/code&gt; will take care of everything else. The problem is, that Docker logs can fill up the disk pretty quickly.&lt;br&gt;&lt;br&gt;
Now with &lt;code&gt;journald&lt;/code&gt; we have one tool to take of logs and by default &lt;code&gt;systemd&lt;/code&gt; will only write a maximum of 4GB logs to your disk. There is no way Docker logs will fill up the disk.&lt;/p&gt;

&lt;p&gt;There are a bunch of configuration options for &lt;code&gt;journald&lt;/code&gt; log size. Here are a few examples if you want to edit them to your use case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=, SystemMaxFiles=, RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize=, RuntimeMaxFiles=¶

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can read more here about &lt;code&gt;journald&lt;/code&gt; config: &lt;a href="https://www.freedesktop.org/software/systemd/man/latest/journald.conf.html?ref=ajfriesen.com" rel="noopener noreferrer"&gt;https://www.freedesktop.org/software/systemd/man/latest/journald.conf.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here for reference the Docker log driver docs: &lt;a href="https://docs.docker.com/config/containers/logging/journald/?ref=ajfriesen.com" rel="noopener noreferrer"&gt;https://docs.docker.com/config/containers/logging/journald/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a great day! 👋&lt;/p&gt;

</description>
      <category>linux</category>
      <category>devops</category>
      <category>docker</category>
      <category>netdata</category>
    </item>
  </channel>
</rss>
