четверг, 8 октября 2015 г.

Docker. Logs. CentOS 7.1

To view the container logs you should run  `docker logs <container id>`.

By default container logs are located in
/var/lib/docker/containers/[CONTAINER ID]/[CONTAINER_ID]-json.log.

Logs are constantly increasing. So they should be cleaned up on a timely base.
In Docker 1.8 and up there is built in logs rotation mechanism.

The current best practice for rotation of Docker logs is to have logrotate use the copytruncate method to copy the logfile and then truncate it in place.

For this create the file `/etc/logrotate.d/docker-container`
with the following content:

/var/lib/docker/containers/*/*.log {
rotate 7
daily
compress
size=1M
missingok
delaycompress
copytruncate
}


Update the logrotate config:
logrotate -fv /etc/logrotate.d/docker-container.

That is all.
There is a possibility to redirect logs to different backends with parameter --log-driver.

By default json driver is used. In case of other log drivers the built in docker command 'docker logs` stops working.

Комментариев нет:

Отправить комментарий