Docker Community Forums

Share and learn in the Docker community.

Issue with Docker container logs rotation

Hi,

I have setup docker swarm with 4 machines and running the stack using yml file. I am trying to setup log rotation but doesn’t seem to be working.

I have done 2 thingsto make it rotate but both are not working.

conf1:

vim /etc/docker/daemon.json:–>

“data-root”: “/opt/docker-image-storage”
{
“log-driver”: “json-file”,
“log-opts”: {
“max-size”: “100m”,
“max-file”: “100”
}
}

Conf2: /etc/logrotate.d/docker -->

/opt/docker-image-storage/containers//.log {
rotate 7
daily
size=100M
dateext
dateformat -%Y-%m-%d-%s
compress
missingok
delaycompress
copytruncate
}

The second config created log rotation file with dateformat attached at end of the file but not based on size.

One more thing i noticed is when the stack was removed the container logs are getting removed. Do we have any way to keep the logs even if we remove the swarm stack or container ?

It will be great if someone can help on configuring rotating the docker logs.

Thanks,
Ahemad

Hello everyone…

Can any one help on this please?

Thanks,
Ahemad