容器日志路径是 /var/lib/docker/containers/"container_id"/"container_id"-json.log
其中 container_id 是对应的容器id
查看各个日志文件大小命令:
for d in $(ls -d /var/lib/docker/containers/*); do ls --time-style=long-iso -lh $d/*-json.log | awk -F' *|/' '{printf("%30s\t%s\t%s %s\t%s\n", "'$(docker ps -af id=${d##*/} --format "table {{.Names}}" | tail -1)'", $5, $6, $7, $14) }'; done
执行输出如下:
[root@localhost ~]# for d in $(ls -d /var/lib/docker/containers/*); do ls --time-style=long-iso -lh $d/*-json.log | awk -F' *|/' '{printf("%30s\t%s\t%s %s\t%s\n", "'$(docker ps -af id=${d##*/} --format "table {{.Names}}" | tail -1)'", $5, $6, $7, $14) }'; donetest1 0 -01-09 22:37 1a037144ddbab011cf8667bf439cc919009505a147b45ac1f76eb870d47b4465-json.logtest2 0 -01-08 06:49 36d1ea4aafea5e7ce39a139e715c7b03c8fe27cb59228902d277bc2d03ad0ccc-json.logtest3 490K -01-09 22:37 4da2f4ed15f8a704b71b00f369d48ded03e89bbb4b7a100a4d10bc1bc670dac0-json.logtest4 1.7M -01-09 22:37 6889f5943e85209f15c58b86376c50cff13ebd57c2056c0ec0d43fce8136ebac-json.logtest5 1 -01-09 11:17 6dde3ea1917168ea8f7d78fd629ed8c41db5cc613baaef723a413cfd94131d4e-json.logtest6 43K-01-09 14:23 7e5223e4729fe0bad8ecf0462bf3416ea38f5b1fa6ee43b682538cb69c4b8da2-json.logtest7 13K-01-09 14:23 a2216eb1c9b97e8b3a81e2d0221c35c89cf770f8ac113a5ff48c29aca48639ce-json.logtest8 313K -01-09 22:37 ccc0451be920dd348468a0c8d80b85ad0965f70f3feb0f0443c5800c29f3e477-json.logtest9 1.6M -01-09 22:37 d392649dc146101b2c580a9e7003493071988ef110a51a766e8d7aece2054953-json.logtest10 1.1M -01-09 22:33 db14cd9d7915e3c17a177ad36645982fd3b93ef548cd1fdc680cfbf0c9dea4ed-json.log
清除指定容器的日志:
echo > /var/lib/docker/containers/$(docker ps --no-trunc -aqf 'name=test1')/*-json.log
其中 test1 是docker 容器名称