Where should I store log files of an application running in Container(docker/kubernetes)?

12/12/2018

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 ?

-- Chandu
containers
docker
kubernetes

2 Answers

12/12/2018

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
-- Viswesn
Source: StackOverflow

12/12/2018

You have a couple of options:

  1. Have you application write to /dev/stdout and/or /dev/stderr.
  2. Write to a log file on the filesystem.

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).

-- yomateo
Source: StackOverflow