{"id":4917,"date":"2026-08-29T22:51:01","date_gmt":"2026-08-29T13:51:01","guid":{"rendered":"https:\/\/donguri3.net\/server-tech\/docker-container-log-disk-space-issue-2\/"},"modified":"2026-08-29T22:51:02","modified_gmt":"2026-08-29T13:51:02","slug":"docker-container-log-disk-space-issue","status":"publish","type":"post","link":"https:\/\/donguri3.net\/en\/server-tech\/virtualization-container-wsl\/docker-container-log-disk-space-issue\/","title":{"rendered":"Solving Docker Container Log Overflow and Disk Space Shortage!"},"content":{"rendered":"<p>When operating Docker, container logs can accumulate in large amounts and put pressure on disk space. Especially in environments using <code>docker-compose<\/code>, if you stick with the default log settings, logs will accumulate indefinitely, and you may find your storage full before you know it.<\/p>\n<p>While investigating the cause of the disk space shortage, I confirmed that the containers had become bloated.<\/p>\n<pre><code>du -shc \/var\/lib\/docker\/containers\/* -x | sort -rh\n9.3G    Total\n7.5G    .\/bba63eea9d895b78284dc1ec7a4ba9d74185dd8ec441c5bc41da954c5d622ab1\n808M    .\/0b01e61f5d2d745b3b0f496077cd6fd94e1c8d0d6aecb2965ad31f38ad639e9c\n\u30fb\u30fb\u30fb<\/code><\/pre>\n<p>Therefore, in this article, we will explain how to manage logs using <code>docker-compose<\/code>.<\/p>\n<h2>Causes of Logs Pressuring Disk Space<\/h2>\n<p>In Docker&#8217;s default configuration, container logs accumulate indefinitely under <code>\/var\/lib\/docker\/containers\/<\/code> using the <code>json-file<\/code> driver. As a result, operating for a long period causes the logs to bloat, which becomes a cause of squeezing disk space.<\/p>\n<h3>Checking the Current Log Size<\/h3>\n<p>To check the log size for each container, use the following command.<\/p>\n<pre><code>sudo du -sh \/var\/lib\/docker\/containers\/*\/*.log<\/code><\/pre>\n<p>This command allows you to understand how large the log files are.<\/p>\n<h2>Log Settings in <code>docker-compose<\/code><\/h2>\n<p>To limit logs in <code>docker-compose.yml<\/code>, add <code>logging<\/code> settings to each service.<\/p>\n<p>For example, to limit the maximum log size to 10MB and the number of retained log files to 3, configure it as follows:<\/p>\n<pre><code>version: '3.8'\n\nservices:\n  my_service:\n    image: my_image\n    logging:\n      driver: \"json-file\"\n      options:\n        max-size: \"10m\"\n        max-file: \"3\"<\/code><\/pre>\n<p>With this setting, when a log reaches 10MB, a new log file is created, and up to 3 log files are retained.<\/p>\n<h3>Where are the <code>docker-compose.yml<\/code> Logs Stored?<\/h3>\n<p>Even if you add <code>logging<\/code> settings to <code>docker-compose.yml<\/code>, the log storage location remains the same as the default. Typically, logs for each container are stored in the following directory:<\/p>\n<pre><code>\/var\/lib\/docker\/containers\/&lt;container_id&gt;\/&lt;container_id&gt;-json.log<\/code><\/pre>\n<p>You can check the <code>container_id<\/code> using <code>docker ps -a<\/code>.<\/p>\n<p>For this reason, even after configuring <code>logging<\/code>, logs will continue to be saved in this directory as long as the <code>json-file<\/code> driver is used.<\/p>\n<h3>Using Other Log Drivers<\/h3>\n<p>Besides <code>json-file<\/code>, Docker allows you to use log drivers such as the following:<\/p>\n<ul>\n<li><code>syslog<\/code>: Send to the system&#8217;s syslog<\/li>\n<li><code>journald<\/code>: Send to systemd&#8217;s journal<\/li>\n<li><code>fluentd<\/code>: Send to Fluentd<\/li>\n<li><code>awslogs<\/code>: Send to AWS CloudWatch Logs<\/li>\n<li><code>none<\/code>: Disable logging<\/li>\n<\/ul>\n<p>For example, when using syslog, configure it like this:<\/p>\n<pre><code>logging:\n  driver: \"syslog\"\n  options:\n    syslog-address: \"udp:\/\/192.168.1.100:514\"<\/code><\/pre>\n<h2>Periodically Clearing Logs<\/h2>\n<p>To delete logs that have already bloated, you can clear the log files with the following command:<\/p>\n<pre><code>echo \"\" | sudo tee \/var\/lib\/docker\/containers\/*\/*.log<\/code><\/pre>\n<p>It is also possible to use cron to periodically delete logs.<\/p>\n<h2>Summary<\/h2>\n<ul>\n<li>Since Docker accumulates logs indefinitely by default, reviewing the settings is necessary<\/li>\n<li>Specify <code>max-size<\/code> and <code>max-file<\/code> in the <code>logging<\/code> configuration of <code>docker-compose.yml<\/code><\/li>\n<li>Even with added configurations, the log destination remains under <code>\/var\/lib\/docker\/containers\/<\/code><\/li>\n<li>Integrating with external log management systems like syslog is also an option<\/li>\n<li>You can save disk space by deleting and managing existing logs<\/li>\n<\/ul>\n<p>When operating Docker, make sure to configure appropriate log settings to use your disk space efficiently!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When operating Docker, container logs can accumulate in large amounts and put pressure on disk space. Especial [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1095,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/donguri3.net\/?p=431","footnotes":""},"categories":[1171],"tags":[18,19,290,1000],"class_list":["post-4917","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-virtualization-container-wsl","tag-docker","tag-docker-compose","tag-json","tag-wsl","en-US"],"_links":{"self":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/comments?post=4917"}],"version-history":[{"count":1,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4917\/revisions"}],"predecessor-version":[{"id":4920,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4917\/revisions\/4920"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media\/1095"}],"wp:attachment":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media?parent=4917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/categories?post=4917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/tags?post=4917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}