Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker View Historical Logs

Background:

For Development purposes I do a lot of docker-compose up -d and docker-compose stop.

To view logs of a container I do either

- docker logs --details --since=1m -t -f container_name
or
- docker inspect --format='{{.LogPath}}' container_name
  cat path-from-previous

The problem is when I want to view 10 days older logs, there are none, the logs just have todays logs.

when I do a docker inspect container_name I get the following

"Created": "todays-timestamp"

my logging is the default config.

"LogConfig": {
     "Type": "json-file",
     "Config": {}
 },
like image 984
Srinath Ganesh Avatar asked Oct 23 '25 14:10

Srinath Ganesh


1 Answers

the reason behind this is because there is no rotation in your docker-logs.

in case you are using a linux system go to:

/etc/logrotate.d/

and create the file docker-container like this => /etc/logrotate.d/docker-container

write this into the file:

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

it takes all builded images and their daily log and rotates + compress them.

you can test this with:

logrotate -fv /etc/logrotate.d/docker-container

enter your docker folder /var/lib/docker/containers/[CONTAINER ID]/ and you can see the rotation.

reference: https://sandro-keil.de/blog/logrotate-for-docker-container/

like image 66
Gabbax0r Avatar answered Oct 26 '25 04:10

Gabbax0r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!