1. Background
Using docker logs to view too many container logs is very inconvenient. It is troublesome to clean up manually every time. I wrote a shell script for batch cleaning.
2. Treatment method
The logs of the docker container are all stored in the /data/docker/lib/docker/containers/
directory, we can delete the corresponding log, here you can create a new shell script
vim cleanDockerLog.sh
Put the following content in
#!/bin/sh
echo "======== start clean docker containers logs ========"
logs=$(find /var/lib/docker/containers/ -name *-json.log)
for log in $logs
do
echo "clean logs : $log"
cat /dev/null > $log
done
echo "======== end clean docker containers logs ========"
Three, perform cleanup
The command to perform the cleanup is as follows
sh ./cleanDockerLog.sh
Check the docker logs -f container ID again, you will find that the log has been completed by the situation
Author: Tang Qingsong
Date: November 12, 2021
WeChat: songboy8888
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。