官方地址:https://docs.docker.com/config/containers/logging/configure/#configure-the-default-logging-driver
查看当前默认log-driver
sudo docker info --format '{{.LoggingDriver}}'
#如果结果为journald
删除––log-driver=journald
sudo vim /etc/sysconfig/docker
––log-driver=journald
sudo vim /etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
重启docker
sudo systemctl restart docker
sudo docker info --format '{{.LoggingDriver}}'
# json-file
ps:注意,此规则,只对新建的容器有效
老容器重新运行的时候推荐添加
docker run -it --log-opt max-size=10m --log-opt max-file=3