Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Docker Logs Persistent

I have been using docker-compose to setup some docker containers. I am aware that the logs can be viewed using docker logs <container-name>.

All logs are being printed to STDOUT and STDERR when the containers are run, there is no log 'file' being generated in the containers.

But these logs (obtained from docker logs command) are removed when their respective containers are removed by commands like docker-compose down or docker-compose rm.

When the containers are created and started again there is a fresh set of logs. No logs from the previous 'run' is present.

I am curious if there is a way to somehow prevent the logs from being removed along with their containers.

Ideally i would like to keep all my previous logs even when the container is removed.

like image 802
bhargav_sk1077 Avatar asked Jun 01 '26 04:06

bhargav_sk1077


1 Answers

I believe you have two ways you can go:

Make containers log into file

You can reconfigure the applications inside the container to write into logfiles rather than stdout/stderr. As you put it, you'd like to keep the logs even when the container is removed. Therefore ensure the files are stored in a (bind) mounted volume.

Reconfigure docker to store logs

Reconfigure docker to use a different logging driver. This can be especially helpful as it prevents you from changing each and every container.

like image 163
Hiran Chaudhuri Avatar answered Jun 02 '26 20:06

Hiran Chaudhuri



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!