docker 查看容器日志大小 清除指定容器日志

容器日志路径是 /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) }'; done
                      test1  0       2022-01-09 22:37        1a037144ddbab011cf8667bf439cc919009505a147b45ac1f76eb870d47b4465-json.log
                      test2  0       2022-01-08 06:49        36d1ea4aafea5e7ce39a139e715c7b03c8fe27cb59228902d277bc2d03ad0ccc-json.log
                      test3  490K    2022-01-09 22:37        4da2f4ed15f8a704b71b00f369d48ded03e89bbb4b7a100a4d10bc1bc670dac0-json.log
                      test4  1.7M    2022-01-09 22:37        6889f5943e85209f15c58b86376c50cff13ebd57c2056c0ec0d43fce8136ebac-json.log
                      test5  1       2022-01-09 11:17        6dde3ea1917168ea8f7d78fd629ed8c41db5cc613baaef723a413cfd94131d4e-json.log
                      test6  43K     2022-01-09 14:23        7e5223e4729fe0bad8ecf0462bf3416ea38f5b1fa6ee43b682538cb69c4b8da2-json.log
                      test7  13K     2022-01-09 14:23        a2216eb1c9b97e8b3a81e2d0221c35c89cf770f8ac113a5ff48c29aca48639ce-json.log
                      test8  313K    2022-01-09 22:37        ccc0451be920dd348468a0c8d80b85ad0965f70f3feb0f0443c5800c29f3e477-json.log
                      test9  1.6M    2022-01-09 22:37        d392649dc146101b2c580a9e7003493071988ef110a51a766e8d7aece2054953-json.log
                     test10  1.1M    2022-01-09 22:33        db14cd9d7915e3c17a177ad36645982fd3b93ef548cd1fdc680cfbf0c9dea4ed-json.log

清除指定容器的日志:

echo > /var/lib/docker/containers/$(docker ps --no-trunc -aqf 'name=test1')/*-json.log

其中 test1 是docker 容器名称

    原文作者:whatday
    原文地址: https://blog.csdn.net/whatday/article/details/122400827
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞