docker limit log file size and number

After recently used docker found a terrible problem, that is, create a container, will occupy disk space, an outrage.

Through access to the site and found that the problem can be avoided.

Terrible path: / var / lib / Docker / Containers

principle:

docker container to create the default is to generate a string of numbers, the system creates a directory for the string of numbers. There are * json.log log files, log container.

If the profile does not modify the docker log, a log generated by default, for example here to 100M, three files retained.

* Json.log generates a first file, the size of the log to 100M, the system will automatically  * json.log file, write  * json.log.1 inside

Wait until * json.log file again to the 100M, the system will automatically  * json.log file, write  * json.log.1 inside, and * json.log.1 file write  * json.log.2 inside.

And so on

I have been tested here, to which a delete files * json.log.2, after a while will generate  * json.log.2 file, if only to retain * json.log.2 file, * json.log.1 log delete the file, the system will now * json.log.1 written to the log file contents * json.log.2 inside.      

First, modify configuration files docker log

  I'm here to modify, log size 100M, retained three documents

vi /etc/docker/daemon.json
{"registry-mirrors": ["https://registry.docker-cn.com"],
"log-driver":"json-file",
"log-opts": {"max-size":"100m", "max-file":"3"}
}

Second, restart dokcer 

systemctl restart docker

Third, create a container

I used here tomcat mirror if the mirror can not pull their own image

docker pull tomcat

docker run --name webtomcat -d -p 8081:8080  -d centos-jdk-tomcat:v20200121

After creating the container will generate a string of numbers, docker will have this number to create a directory of a container

/var/lib/docker/containers/5c0c836b5aaf2088e04d4df1ed9cc3aa770f300ca097b9a8c70416983ed31bd8

Fourth, observe the log size case

cd /var/lib/docker/containers/5c0c836b5aaf2088e04d4df1ed9cc3aa770f300ca097b9a8c70416983ed31bd8

It found that the log file has been generated two files, and then wait to see if a file is also generated.

 

 

 Finally we found, and generate a file

 

 

 4.1 observe whether the log is written into circulation

I last wrote here in 1111 * .1 log file

I last wrote here in 2222 * .2 log file

 

 

 

 

 

 4.2 observe whether there is a change log file

需要登录*.log 这个文件变为100M后,发现变小了,发现他的日志写入到了 *.1里面,而*.1的日志写入到了 *.2里面

 

 

 

 

 

 

五、这里遇到的问题

如果修改docker日志配置文件,重启docker ,原来的容器不会生产三个文件,不生效,需要重新创建容器

Guess you like

Origin www.cnblogs.com/pythonx/p/12320959.html