5. Configuring Logging for Containerised Applications Flashcards
What are application logs designed to do?
Report events that occur during the execution of a program.
How do software developers implement logging in their applications?
They code log writing within their source code at appropriate locations for reporting.
How are log messages provided to us and for what purpose?
They are provided as output during program execution for the purposes of debugging.
What can be said about the responsibilities of a twelve-factor app when it comes to writing and managing log files?
A twelve-factor app never concerns itself with routing or storage of its output system. It should not attempt to write or manage log files. Instead, each running process writes its event stream, unbuffered, to STDOUT.
What is a stream in the context of a process’s communications?
A communication channel between the process and its environment, in which data flows from one end of the stream to another.
This is how an application’s process receives its input and provides its output.
Where are twelve-factor applications are recommended to write their output stream to?
The standard out (STDOUT).
What is STDERR?
Standard Error is an output channel similar to Standard Out (STDOUT), but used separately to distinguish program output from any generated errors.
Sometimes, STDOUT and STDERR are combined.
Which streams of an application output does Docker capture and store for containers?
Both the Standard Out (STDOUT) and Standard Error (STDERR).
What can be said about writing logs directly to files from Docker containers?
This is considered a bad practice and must be avoided if we can. We must instead send the logs to STDOUT or STDERR.
If we have a legacy application that is configure to write its logs to a file and we instead want to send logs to a source, how can we get around this?
It’s possible to link the file where the app writes logs to a stream — a symbolic link is a Linux kernel mechanism for achieving this using the ln
command.
Dockerfile
~~~
RUN ln -sf /dev/stdout /var/log/nginx/access.log
~~~
What are the logging mechanisms provided by Docker?
- Pluggable system — implemented using pluggable drivers.
- Batteries included — inbuilt options for managing logs locally.
- Third-party vendors — popular logging solutions are available.
What are the three popular logging drivers for Docker containers?
- json-file — default driver that stores logs locally in JSON format (legacy/suboptimal).
- local — flexible and more performant file-based logging solution.
- journald — logs sent to journald service running on the Docker host.
How can we change the default logging driver for the Docker daemon?
It requires reconfiguration of the daemon, which can be achieved using its configuration file daemon.json
.
{ # ... "log-driver": "local", "log-opts": { "max-size": "10m", "max-file": "6" } # ... }
How can we run containers with an alternative logging setup than the one configured for the Docker daemon?
By using the --log-driver
option when running docker run
and providing it with the name of the driver.
~~~
docker run –name todo –log-driver local …
``
How can we inspect the logs of a container?
By running docker logs
and providing it with the name or ID of the container to be inspected.
docker logs todo