I have to port an application (C/C++) to docker container. The application writes to log files in file system. How and where to store log file when application runs in container ?
I would recommend the following for writing the log file of the application and to see the stdout and stderr of the logs on running the command
$docker logs <docker-name>
This requires change in the Dockerfile and this is what you can see in most of the dockers like nginx, httpd.
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/<app-name>/access.log \
&& ln -sf /dev/stderr /var/log/<app-name>/error.log
You have a couple of options:
/dev/stdout
and/or /dev/stderr
.What it boils down to is "log collection" and how you want to go about collecting this data. Logging to stdout and stderr may be the simplest but it doesn't help you if you want to acquire and analyze very specific log data about your application.
Docker supports multiple "log drivers" which will help extract, transform and lift the log data to an external source ("ETL"). See: https://docs.docker.com/config/containers/logging/configure/
For all of my applications I use FluentD and the docker log collector so I can do "smart" things with the data (https://fluentd.org).