<?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: Serepas Filippas</title>
    <description>The latest articles on DEV Community by Serepas Filippas (@spartakos87).</description>
    <link>https://dev.to/spartakos87</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%2F61101%2F0bce1ac5-c7ab-4573-9f8b-a09c5cb91b47.png</url>
      <title>DEV Community: Serepas Filippas</title>
      <link>https://dev.to/spartakos87</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/spartakos87"/>
    <language>en</language>
    <item>
      <title>Docker Logs, continue....</title>
      <dc:creator>Serepas Filippas</dc:creator>
      <pubDate>Tue, 21 Feb 2023 17:55:37 +0000</pubDate>
      <link>https://dev.to/spartakos87/docker-logs-continue-ld0</link>
      <guid>https://dev.to/spartakos87/docker-logs-continue-ld0</guid>
      <description>&lt;p&gt;In my previous &lt;a href="https://dev.to/spartakos87/docker-logs-set-limits-fe0"&gt;post&lt;/a&gt; I have explained how to set limits in docker logs. But after that we can see that, for some reason, docker after reach the max-size create a second file with extension &lt;strong&gt;log.1&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/s239QJIh56sRW/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/s239QJIh56sRW/giphy.gif" width="480" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I don't know, yet, why this happening but, after the lattest file reach again the max-size, docker start write, from begin the first file..&lt;/p&gt;

&lt;h1&gt;
  
  
  Set limits to the number of logs files!!!
&lt;/h1&gt;

&lt;p&gt;So you need to add one more argument to your &lt;em&gt;docker-compose.yml&lt;/em&gt;, for example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;logging:
       driver: &lt;span class="s2"&gt;"json-file"&lt;/span&gt;
       options:
           max-size: &lt;span class="s2"&gt;"100k"&lt;/span&gt;
           max-file: &lt;span class="s2"&gt;"3"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now docker will create three logs files with these extensions:&lt;br&gt;
&lt;strong&gt;.log&lt;/strong&gt;, &lt;strong&gt;.log.1&lt;/strong&gt;, &lt;strong&gt;.log.2&lt;/strong&gt;&lt;br&gt;
When first one hit the max-size will create the next one and etc.&lt;br&gt;
When docker reach the limit in last file &lt;strong&gt;.log.2&lt;/strong&gt; will recreate the first one &lt;strong&gt;.log&lt;/strong&gt; .&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
    </item>
    <item>
      <title>Docker Logs, set limits!</title>
      <dc:creator>Serepas Filippas</dc:creator>
      <pubDate>Mon, 06 Feb 2023 18:34:28 +0000</pubDate>
      <link>https://dev.to/spartakos87/docker-logs-set-limits-fe0</link>
      <guid>https://dev.to/spartakos87/docker-logs-set-limits-fe0</guid>
      <description>&lt;h1&gt;
  
  
  The problem...
&lt;/h1&gt;

&lt;p&gt;I have a docker-compose.yaml which contains a simple python script. The job of this script is to subscribe to MQTT broker and then write these messages to a database. &lt;/p&gt;

&lt;h2&gt;
  
  
  The mistake...
&lt;/h2&gt;

&lt;p&gt;Inside this script I have a simple innocent print statement, which prints the captured message.&lt;br&gt;
We talk about 30 messages per second, and this service already runs for 3 plus months. So..., a lot of messages.&lt;/p&gt;
&lt;h2&gt;
  
  
  I need more space!!!
&lt;/h2&gt;

&lt;p&gt;First of all, this script runs in Ubuntu server. At some point the hard disk doesn't have enough space. My first though is that there is much data inside my database.&lt;br&gt;
But the problem here is that I get messages every second (~3600x30 messages!) which eventually I replace with their average value per hour. Again I think the problem is the database.&lt;/p&gt;
&lt;h2&gt;
  
  
  VACUUM IT!!!
&lt;/h2&gt;

&lt;p&gt;I use &lt;strong&gt;Postgresql&lt;/strong&gt;, so, I read the &lt;a href="https://www.postgresql.org/docs/current/sql-vacuum.html" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;. &lt;br&gt;
Here we are! Let's release some space. At this point I don't want to use the &lt;strong&gt;VACUUM FULL&lt;/strong&gt; because it causes downtimes...&lt;br&gt;
After that, nothing changed dramatically in my server's hard drive..&lt;/p&gt;
&lt;h2&gt;
  
  
  Docker df
&lt;/h2&gt;

&lt;p&gt;I think my first move should be this one. Check the space which is taken by my docker container,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker system &lt;span class="nb"&gt;df&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hmmm, here I am missing ~6.5Gb of space which at that point I assumed was being taken up by docker... somehow...&lt;/p&gt;

&lt;h2&gt;
  
  
  Logs, Logs everywhere..
&lt;/h2&gt;

&lt;p&gt;Next move is to see the logs of the container&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker logs &amp;lt;container &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I see all these print statements which start from the beginning of container's existence.&lt;br&gt;
So, I thought where these logs are stored?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; docker inspect &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{{.LogPath}}'&lt;/span&gt; &amp;lt;my-app or container-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result will be something like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/var/lib/docker/containers/46d66d306b4a7f95051dbf2aa7b27864d78d84bfac7dc685c4b94985a1ee30c5/46d66d306b4a7f95051dbf2aa7b27864d78d84bfac7dc685c4b94985a1ee30c5-json.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you are!!!&lt;br&gt;
Ok, then I cd to this directory and run,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see 6.5Gb of logs!!!&lt;br&gt;
Here was my precious Gb!!!&lt;br&gt;
&lt;a href="https://i.giphy.com/media/3oFyCVxsQn6RBa0r5u/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3oFyCVxsQn6RBa0r5u/giphy.gif" width="427" height="240"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How clear this logs?
&lt;/h2&gt;

&lt;p&gt;The first fast and easy way, without need to re-build your container is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;sh &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s1"&gt;'echo "" &amp;gt; $(docker inspect --format="{{.LogPath}}" my-app)'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be aware, this is a temporary solution! You will come up with the same problem in the near future!&lt;/p&gt;

&lt;h2&gt;
  
  
  Set limits in docker-compose
&lt;/h2&gt;

&lt;p&gt;You can set limits of logs for your container in your docker-compose.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;logging&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;driver&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;json-file"&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;max-size&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;50m&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we set limit of 50mb of log file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set limits in docker run
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--log-driver&lt;/span&gt; &lt;span class="nb"&gt;local&lt;/span&gt; &lt;span class="nt"&gt;--log-opt&lt;/span&gt; max-size&lt;span class="o"&gt;=&lt;/span&gt;10m &lt;span class="se"&gt;\&lt;/span&gt;
      alpine &lt;span class="nb"&gt;echo &lt;/span&gt;hello world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another example, set 10mb limit of logs with docker command&lt;br&gt;
&lt;a href="https://dev.to/spartakos87/docker-logs-continue-ld0"&gt;To be continued...&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Sources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.misterpki.com/docker-log-file-size/" rel="noopener noreferrer"&gt;https://www.misterpki.com/docker-log-file-size/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.howtogeek.com/devops/how-to-clear-logs-of-running-docker-containers/" rel="noopener noreferrer"&gt;https://www.howtogeek.com/devops/how-to-clear-logs-of-running-docker-containers/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/config/containers/logging/local/" rel="noopener noreferrer"&gt;https://docs.docker.com/config/containers/logging/local/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

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