6

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.

1 Answers1

1

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.

Queeg
  • 7,748
  • 1
  • 16
  • 42