5. Configuring Logging for Containerised Applications Flashcards

1
Q

What are application logs designed to do?

A

Report events that occur during the execution of a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do software developers implement logging in their applications?

A

They code log writing within their source code at appropriate locations for reporting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are log messages provided to us and for what purpose?

A

They are provided as output during program execution for the purposes of debugging.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What can be said about the responsibilities of a twelve-factor app when it comes to writing and managing log files?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a stream in the context of a process’s communications?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where are twelve-factor applications are recommended to write their output stream to?

A

The standard out (STDOUT).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is STDERR?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which streams of an application output does Docker capture and store for containers?

A

Both the Standard Out (STDOUT) and Standard Error (STDERR).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What can be said about writing logs directly to files from Docker containers?

A

This is considered a bad practice and must be avoided if we can. We must instead send the logs to STDOUT or STDERR.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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?

A

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
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the logging mechanisms provided by Docker?

A
  1. Pluggable system — implemented using pluggable drivers.
  2. Batteries included — inbuilt options for managing logs locally.
  3. Third-party vendors — popular logging solutions are available.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the three popular logging drivers for Docker containers?

A
  1. json-file — default driver that stores logs locally in JSON format (legacy/suboptimal).
  2. local — flexible and more performant file-based logging solution.
  3. journald — logs sent to journald service running on the Docker host.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can we change the default logging driver for the Docker daemon?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can we run containers with an alternative logging setup than the one configured for the Docker daemon?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can we inspect the logs of a container?

A

By running docker logs and providing it with the name or ID of the container to be inspected.

docker logs todo
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What can be said about the local availability of logs that are sent from a container to an external logging service, starting from Docker version 20.10?

A

That the versions hereafter requires to view logs locally when using any driver other than json-file, local, or journald. This means that the logs sent to an external logging system will also be available locally for a developer while iterating over the inner loop of code development.

17
Q

What command-line options are there to customise the log output when using docker logs?

A
  1. --details — display additional info from tag.
  2. --follow — follow the log output.
  3. --tail — show last N lines of log output.
  4. --since — show log output since a point in time.
  5. --until — show log output to a point in time.
  6. --timestamps — annotate logs with a timestamp.
18
Q

How do we inspect the details about the details on the configuration of Docker daemon?

A

By using the docker info command.

19
Q

From the command-line, how can we find out the configured logging driver of the Docker daemon?

A

By executing `docker info -f “{{.LoggingDriver}}”

20
Q

Where is the Docker daemon configuration file located on Linux, and where is it in MacOS?

A
LINUX
Inside the `/etc/docker` directory.

/etc/docker/daemon.json
~~~
```

MAC
Inside the `~/.docker` directory.

~/.docker/daemon.json
~~~
~~~

21
Q

How can you configure the Docker daemon to use a log driver other than the default one?

A

By adding or setting the value of the log-driver entry in daemon.json and restarting the docker service by running the following:

MAC
~~~
killall Docker && open /Applications/Docker.app
~~~

LINUX
~~~
sudo systemtcl restart docker.service
~~~

22
Q

How do you run a container in the background and print the container ID?

A

By using the -detach (or -d) option for the docker run command.

docker run -r //...
23
Q

How do you assign a name to a container to run?

A

By using the --name option for the docker run command and passing it the name to assign.

docker run --name todo //...
24
Q

How do you initiate a sort of “watch” on a running detached container’s logs to print logs in real time?

A

By running docker logs with the -f (or --follow) option.

docker logs -f todo