Answers: <p>You can copy the actual logs from <code>/var/lib/docker/containers/&lt;container id&gt;/&lt;container id&gt;-json.log</code> to archive them then clear the logs manually (since you have only 2 services, influxdb and grafana). The containers won't stop with this procedure.</p>
  <p>There is a <a href="https://stackoverflow.com/a/42510314/3756843">full and clear answer</a> on <a href="https://stackoverflow.com/questions/42510002/how-to-clear-the-logs-properly-for-a-docker-container">this StackOverflow question</a> about clearing container logs. It also explains how to configure the Docker daemon to rotate logs.</p>
  <blockquote>
  <p>From <a href="https://serverfault.com/q/637996/351549">this question</a> there's a one-liner that you can run:</p>
  <pre><code>echo &quot;&quot; &gt; $(docker inspect --format='{{.LogPath}}' &lt;container_name_or_id&gt;)
  </code></pre>
  <p>[...]</p>
  <p>You can also set this as part of your <a href="https://docs.docker.com/engine/reference/commandline/dockerd/#on-linux" rel="nofollow noreferrer">daemon.json</a> file instead of modifying your startup scripts:</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>@BMitch - <a href="https://stackoverflow.com/a/42510314/3756843">https://stackoverflow.com/a/42510314/3756843</a></p>
  </blockquote>
  <p>As adviced, you should do this only until you configure the Docker daemon as your needs.</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-05-21T08:10:04.310Z
Answers: 2021-05-21T08:10:04.310Z
Answers: Paul Rey
Answers: <p>You can update the daemon.json config to specify your normal syslog driver (assuming linux) to use the normal syslog logrotation method for keeping log files or shipping off-box</p>
  <p><a href="https://docs.docker.com/config/containers/logging/syslog/" rel="nofollow noreferrer">https://docs.docker.com/config/containers/logging/syslog/</a></p>
  <pre><code>{
    &quot;log-driver&quot;: &quot;syslog&quot;,
    &quot;log-opts&quot;: {
      &quot;syslog-address&quot;: &quot;udp://localhost:514&quot;
    }
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-05-20T17:47:36.670Z
Answers: 2021-05-20T17:47:36.670Z
Answers: Peter Turner
Body: <p>My question is more on the concept or best practices to follow.</p>
  <p>I have two docker containers running InfluxDB and Grafana (monitoring applications). I have mounted external volume to each.</p>
  <p>now, the problem is, these containers are running for quite some time (1 year approx), i am little bit worried about Host VM resources on which these containers are running. specifically storage resources as these are monitoring applications, which may be storing some data for historical purpose as well.</p>
  <p>So, my ask is, what is the best practice to manage logs/data stored in docker volume. I don't want my Host VM to go out of storage and crash my containers.</p>
  <p>Any possible solution, if we can rotate stored data so that my container won't stop and i have the historical data as well. or if possible from application point of view (InfluxDB and Grafana) to archive old data.</p>
  <p>Thanks in advance... Please let me know if you need more details on this.</p>
  <p>below is my docker-compose.yml file</p>
  <pre><code>version: &quot;2&quot;
  services:
    grafana:
      image: grafana/grafana
      container_name: grafana
      user: root
      privileged: true
      restart: always
      ports:
        - 3000:3000
      networks:
        - monitoring
      volumes:
        - grafana-volume:/var/lib/grafana
    influxdb:
      image: influxdb
      container_name: influxdb
      restart: always
      ports:
        - 8086:8086
      networks:
        - monitoring
      volumes:
        - influxdb-volume:/var/lib/influxdb
  networks:
    monitoring:
  volumes:
    grafana-volume:
      external: true
    influxdb-volume:
      external: true
  </code></pre>
  
Comments: CC BY-SA 4.0
Comments: 2021-05-20T14:36:40.360Z
Comments: What are your requirements for log storage?  There is a log-driver option in docker
Comments: Peter Turner
Comments: CC BY-SA 4.0
Comments: 2021-05-20T17:31:48.447Z
Comments: actually, I want to rotate the logs, archiving old logs. 
  can you please share any link for docker log-driver ?
Comments: Chandella07
Tags: <docker><docker-compose><monitoring><databases><grafana>
Title: Log/Data rotation in Docker Container
UserDisplayName: Chandella07
ThreadText: # Log/Data rotation in Docker Container
  
  (Asked by: username_0 on 2021-05-18)
  
  My question is more on the concept or best practices to follow.
  
  I have two docker containers running InfluxDB and Grafana (monitoring applications). I have mounted external volume to each.
  
  now, the problem is, these containers are running for quite some time (1 year approx), i am little bit worried about Host VM resources on which these containers are running. specifically storage resources as these are monitoring applications, which may be storing some data for historical purpose as well.
  
  So, my ask is, what is the best practice to manage logs/data stored in docker volume. I don't want my Host VM to go out of storage and crash my containers.
  
  Any possible solution, if we can rotate stored data so that my container won't stop and i have the historical data as well. or if possible from application point of view (InfluxDB and Grafana) to archive old data.
  
  Thanks in advance... Please let me know if you need more details on this.
  
  below is my docker-compose.yml file
  
  ```
  version: "2"
  services:
    grafana:
      image: grafana/grafana
      container_name: grafana
      user: root
      privileged: true
      restart: always
      ports:
        - 3000:3000
      networks:
        - monitoring
      volumes:
        - grafana-volume:/var/lib/grafana
    influxdb:
      image: influxdb
      container_name: influxdb
      restart: always
      ports:
        - 8086:8086
      networks:
        - monitoring
      volumes:
        - influxdb-volume:/var/lib/influxdb
  networks:
    monitoring:
  volumes:
    grafana-volume:
      external: true
    influxdb-volume:
      external: true
  
  ```
  
  **Tags:** docker, docker-compose, monitoring, databases, grafana
  
  > **Comments:**
  > **username_1**: What are your requirements for log storage?  There is a log-driver option in docker  
  > **username_0**: actually, I want to rotate the logs, archiving old logs.  can you please share any link for docker log-driver ?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2021-05-21. Score: 2 | Accepted answer
  
  You can copy the actual logs from `/var/lib/docker/containers/<container id>/<container id>-json.log` to archive them then clear the logs manually (since you have only 2 services, influxdb and grafana). The containers won't stop with this procedure.
  
  There is a [full and clear answer](https://stackoverflow.com/a/42510314/3756843) on [this StackOverflow question](https://stackoverflow.com/questions/42510002/how-to-clear-the-logs-properly-for-a-docker-container) about clearing container logs. It also explains how to configure the Docker daemon to rotate logs.
  
  > From [this question](https://serverfault.com/q/637996/351549) there's a one-liner that you can run:
  >
  > ```
  > echo "" > $(docker inspect --format='{{.LogPath}}' <container_name_or_id>)
  >
  > ```
  >
  > [...]
  >
  > You can also set this as part of your [daemon.json](https://docs.docker.com/engine/reference/commandline/dockerd/#on-linux) file instead of modifying your startup scripts:
  >
  > ```
  > {
  >   "log-driver": "json-file",
  >   "log-opts": {"max-size": "10m", "max-file": "3"}
  > }
  >
  > ```
  >
  > @BMitch - <https://stackoverflow.com/a/42510314/3756843>
  
  As adviced, you should do this only until you configure the Docker daemon as your needs.
  
  
  ---
  
  ### Answer by username_1 on 2021-05-20. Score: 1
  
  You can update the daemon.json config to specify your normal syslog driver (assuming linux) to use the normal syslog logrotation method for keeping log files or shipping off-box
  
  <https://docs.docker.com/config/containers/logging/syslog/>
  
  ```
  {
    "log-driver": "syslog",
    "log-opts": {
      "syslog-address": "udp://localhost:514"
    }
  }
  
  ```
  
  
  ---
  
  