Answers: <p>One way to limit docker logs is to specify limits in docker daemon's config file.</p>
  <p>You can put this in <code>/etc/docker/daemon.json</code></p>
  <pre><code>{
    &quot;log-driver&quot;: &quot;json-file&quot;,
    &quot;log-opts&quot;: {
      &quot;max-size&quot;: &quot;10m&quot;,
      &quot;max-file&quot;: &quot;3&quot; 
    }
  }
  </code></pre>
  <p>and then restart your docker daemon.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-12-13T09:23:25.853Z
Answers: 2020-12-13T09:23:25.853Z
Answers: Oli
Answers: <pre><code>service:
    api:
      build:
        context: .
        dockerfile: Dockerfile
      container_name: api
      ports:
        - &quot;9000:9000&quot;
      networks:
        - rex
      logging:
        driver: &quot;json-file&quot;
        options:
          max-size: &quot;10m&quot;   # Limit log file size to 10 megabytes
          max-file: &quot;3&quot;     # Limit number of log files to 3
  </code></pre>
  <p>Use this for Docker swarm or docker compose</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-08-14T09:48:28.577Z
Answers: 2024-08-14T09:48:28.577Z
Answers: playwithcode
Body: <p><strong>Context</strong>*</p>
  <p>I forgot to pass the &quot;--tail&quot; options to the &quot;docker logs&quot; command when inspecting a running container. The affected container dumps tens of millions of logs.</p>
  <p>The command line was something like:</p>
  <pre><code>  $ docker logs contianer01 | vim -
  </code></pre>
  <p>When executing such line my server becomes completely unresponsive for minutes due to exhaution of free RAM memory with peak loads beyond 60x100%. I loose control of the terminal and ssh connection fails.</p>
  <p><em><strong>Question</strong></em>:
  Is it any tunning in docker to &quot;fail fast&quot; and forbid such big log outputs in first place (maybe tunning ulimits for the docker daemon in some config file)</p>
  <p><em><strong>NOTE</strong></em>: Probably &quot;ulimit&quot;, &quot;resource-control&quot; and &quot;linux&quot; tags must be added to this question but I have not enough &quot;reputation&quot;.</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-12-15T20:27:59.063Z
Comments: For the record, what eats space here is `vim`, you wouldn't have a problem with  `less` for exemple which would stream the output and not load it entirely in memory.
Comments: Tensibai
Tags: <docker><linux>
Title: any way to limit "docker logs" output by default?
UserDisplayName: earizon
ThreadText: # any way to limit "docker logs" output by default?
  
  (Asked by: username_0 on 2020-12-08)
  
  **Context**\*
  
  I forgot to pass the "--tail" options to the "docker logs" command when inspecting a running container. The affected container dumps tens of millions of logs.
  
  The command line was something like:
  
  ```
    $ docker logs contianer01 | vim -
  
  ```
  
  When executing such line my server becomes completely unresponsive for minutes due to exhaution of free RAM memory with peak loads beyond 60x100%. I loose control of the terminal and ssh connection fails.
  
  ***Question***:
  Is it any tunning in docker to "fail fast" and forbid such big log outputs in first place (maybe tunning ulimits for the docker daemon in some config file)
  
  ***NOTE***: Probably "ulimit", "resource-control" and "linux" tags must be added to this question but I have not enough "reputation".
  
  **Tags:** docker, linux
  
  > **Comments:**
  > **username_1**: For the record, what eats space here is `vim`, you wouldn't have a problem with  `less` for exemple which would stream the output and not load it entirely in memory.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-12-13. Score: 1 | Accepted answer
  
  One way to limit docker logs is to specify limits in docker daemon's config file.
  
  You can put this in `/etc/docker/daemon.json`
  
  ```
  {
    "log-driver": "json-file",
    "log-opts": {
      "max-size": "10m",
      "max-file": "3" 
    }
  }
  
  ```
  
  and then restart your docker daemon.
  
  
  ---
  
  ### Answer by username_3 on 2024-08-14. Score: 1
  
  ```
  service:
    api:
      build:
        context: .
        dockerfile: Dockerfile
      container_name: api
      ports:
        - "9000:9000"
      networks:
        - rex
      logging:
        driver: "json-file"
        options:
          max-size: "10m"   # Limit log file size to 10 megabytes
          max-file: "3"     # Limit number of log files to 3
  
  ```
  
  Use this for Docker swarm or docker compose
  
  
  ---
  
  