问题
容器日志一般存放在/var/lib/docker/containers/container_id/
下面,以json.log
结尾的文件(业务日志)很大.
处理
- 临时清空日志
# 注意不能用rm命令
cat /dev/null > /var/lib/docker/containers/容器id/容器id-json.log
- 如果是docker-compose
通过配置容器docker-compose.yml
的max-size
选项来实现:
nginx:
image: nginx:1.12.1
restart: always
logging:
driver: "json-file"
options:
max-size: "5g"
- 限制docker容器日志大小
// vim /etc/docker/daemon.json
{
"log-driver":"json-file",
"log-opts": {"max-size":"500m", "max-file":"3"}
}
重启docker生效
systemctl daemon-reload
systemctl restart docker