Docker set –log-opt on running container

dockerlogging

I am running into a little problem with my Docker logs on a critical piece of infrastructure. Apparently we started the container without the --log-opt max-size setting so the logs now grow at a pretty alarming rate. I would like to avoid having to restart the service but need to limit the amount of logfiles docker is writing to disk.

Is there a way to set the max log size without restarting the container?

We are running docker 1.10.3-0~trusty on `Ubuntu 14.04

Best Answer

You can use logrotate. It is installed by default on Ubuntu servers and you can check /etc/logrotate.d/ for existing logrotate policies.

Following is an example policy to rotate log files daily. You can copy-paste this to /etc/logrotate.d/docker-logs

/var/lib/docker/containers/*/*.log {
  daily
  rotate 7
  compress
  missingok
  copytruncate
}

You can read more about logrotate here