本文及资源最后更新时间 2020-11-28 by sky995
docker运行时间长了,会有大量的日志
如果不定时清理,可能会导致磁盘空间不足
在linux上,容器日志一般存放在/var/lib/docker/containers/container_id/下面, 以json.log结尾的文件(业务日志)很大,查看各个日志文件大小的脚本docker_log_size.sh,内容如下
<code><span class="lit">1</span> <span class="com">#!/bin/sh </span> <span class="lit">2</span><span class="pln"> echo </span><span class="str">"======== start clean docker containers logs ========"</span> <span class="lit">3</span><span class="pln"> logs</span><span class="pun">=</span><span class="pln">$</span><span class="pun">(</span><span class="pln">find </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">docker</span><span class="pun">/</span><span class="pln">containers</span><span class="pun">/</span> <span class="pun">-</span><span class="pln">name </span><span class="pun">*-</span><span class="pln">json</span><span class="pun">.</span><span class="pln">log</span><span class="pun">)</span> <span class="lit">4</span> <span class="kwd">for</span><span class="pln"> log </span><span class="kwd">in</span><span class="pln"> $logs </span><span class="lit">5</span> <span class="kwd">do</span> <span class="lit">6</span><span class="pln"> echo </span><span class="str">"clean logs : $log"</span> <span class="lit">7</span><span class="pln"> cat </span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="kwd">null</span> <span class="pun">></span><span class="pln"> $log </span><span class="lit">8</span> <span class="kwd">done</span> <span class="lit">9</span><span class="pln"> echo </span><span class="str">"======== end clean docker containers logs ========"</span> </code>
当然,如果要根治的话,在启动的时候就要限制日志log的大小