Docker Logging: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(10 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
=Standard Syntax=
+
= Syntax =
*Der Standard Syntax sieht wie folgt aus.
 
docker logs [OPTIONS] NAME
 
docker service logs [OPTIONS] NAME
 
*Docker verwendet einen JSON-Protokolltreiber, der Protokolle im JSON-Format in eine containerspezifische Datei auf dem Host schreibt.
 
*Normalerweise werden Standard Output und Standard Error in dem Docker-log übergeben.
 
  
=Was ist ein Protokolltreiber?=
+
* Für einen Container
*Protokollierungstreiber sind Mechanismen von Docker zum Sammeln von Daten aus laufenden Containern und Diensten.
+
* '''docker logs [OPTIONS] NAME'''
*Immer wenn ein neuer Container erstellt wird, stellt Docker automatisch den JSON-Datei-Protokolltreiber bereit, wenn keine andere Protokolltreiberoption angegeben wurde.  
+
* Für Services/Tasks eines Docker-Swarms
 +
* '''docker service logs [OPTIONS] NAME'''
 +
* Normalerweise werden Standard Output und Standard Error dem Docker-log übergeben.
  
 +
= Beispiele =
  
==Beispiel fürs anzeigen verschiedener Docker Informationen==
+
== Containerprotokolle anzeigen ==
*Containerprotokolle anzeigen:
 
docker logs nginx
 
<pre>
 
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
 
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
 
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
 
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
 
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
 
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
 
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
 
/docker-entrypoint.sh: Configuration complete; ready for start up
 
2023/02/13 07:11:47 [notice] 1#1: using the "epoll" event method
 
2023/02/13 07:11:47 [notice] 1#1: nginx/1.23.3
 
2023/02/13 07:11:47 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
 
2023/02/13 07:11:47 [notice] 1#1: OS: Linux 5.4.0-137-generic
 
2023/02/13 07:11:47 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
 
2023/02/13 07:11:47 [notice] 1#1: start worker processes
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 29
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 30
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 31
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 32
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 33
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 34
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 35
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 36
 
  
</pre>
+
* '''docker logs nginx'''
*Nur neue Protokolle anzeigen:
 
docker logs -f nginx
 
<pre>
 
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
 
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
 
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
 
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
 
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
 
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
 
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
 
/docker-entrypoint.sh: Configuration complete; ready for start up
 
2023/02/13 07:11:47 [notice] 1#1: using the "epoll" event method
 
2023/02/13 07:11:47 [notice] 1#1: nginx/1.23.3
 
2023/02/13 07:11:47 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
 
2023/02/13 07:11:47 [notice] 1#1: OS: Linux 5.4.0-137-generic
 
2023/02/13 07:11:47 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
 
2023/02/13 07:11:47 [notice] 1#1: start worker processes
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 29
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 30
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 31
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 32
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 33
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 34
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 35
 
2023/02/13 07:11:47 [notice] 1#1: start worker process 36
 
  
</pre>
+
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
*CPU- und Speicherauslastung anzeigen:  
+
  /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
  docker stats
+
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
<pre>
+
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
CONTAINER ID  NAME      CPU %    MEM USAGE / LIMIT    MEM %    NET I/O      BLOCK I/O        PIDS
+
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
42f4afd9ad3d  nginx     0.00%    9.316MiB / 11.46GiB  0.08%    1.53kB / 0B  4.1kB / 8.19kB  9
+
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
</pre>
+
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
*CPU- und Speicherauslastung für bestimmte Container anzeigen:  
+
  /docker-entrypoint.sh: Configuration complete; ready for start up
  docker stats nginx
+
2023/02/13 07:11:47 [notice] 1#1: using the "epoll" event method
<pre>
+
2023/02/13 07:11:47 [notice] 1#1: nginx/1.23.3
CONTAINER ID  NAME      CPU %    MEM USAGE / LIMIT    MEM %    NET I/O      BLOCK I/O        PIDS
+
2023/02/13 07:11:47 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
42f4afd9ad3d  nginx    0.00%    9.316MiB / 11.46GiB  0.08%    1.53kB / 0B  4.1kB / 8.19kB  9
+
2023/02/13 07:11:47 [notice] 1#1: OS: Linux 5.4.0-137-generic
</pre>
+
2023/02/13 07:11:47 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
*Laufende Prozesse in einem Container anzeigen:  
+
  2023/02/13 07:11:47 [notice] 1#1: start worker processes
  docker top nginx
+
2023/02/13 07:11:47 [notice] 1#1: start worker process 29
<pre>
+
2023/02/13 07:11:47 [notice] 1#1: start worker process 30
UID                PID                PPID                C                  STIME              TTY                TIME                CMD
+
2023/02/13 07:11:47 [notice] 1#1: start worker process 31
root                112223              112199              0                  07:11               ?                  00:00:00            nginx: master process nginx -g daemon off;
+
2023/02/13 07:11:47 [notice] 1#1: start worker process 32
systemd+            112291              112223              0                  07:11               ?                  00:00:00            nginx: worker process
+
2023/02/13 07:11:47 [notice] 1#1: start worker process 33
systemd+            112292              112223              0                  07:11               ?                  00:00:00            nginx: worker process
+
2023/02/13 07:11:47 [notice] 1#1: start worker process 34
systemd+            112293              112223              0                  07:11               ?                  00:00:00            nginx: worker process
+
2023/02/13 07:11:47 [notice] 1#1: start worker process 35
systemd+            112294              112223              0                  07:11               ?                  00:00:00            nginx: worker process
+
2023/02/13 07:11:47 [notice] 1#1: start worker process 36
systemd+            112295              112223              0                  07:11               ?                  00:00:00            nginx: worker process
 
systemd+            112296              112223              0                  07:11               ?                  00:00:00            nginx: worker process
 
systemd+            112297              112223              0                  07:11               ?                  00:00:00            nginx: worker process
 
systemd+            112298              112223              0                  07:11               ?                  00:00:00            nginx: worker process
 
  
</pre>
+
== neu einkommende Protokolleinträge anzeigen ==
 +
 
 +
* '''docker logs -f nginx'''
 +
 
 +
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
 +
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
 +
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
 +
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
 +
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
 +
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
 +
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
 +
/docker-entrypoint.sh: Configuration complete; ready for start up
 +
2023/02/13 07:11:47 [notice] 1#1: using the "epoll" event method
 +
2023/02/13 07:11:47 [notice] 1#1: nginx/1.23.3
 +
2023/02/13 07:11:47 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
 +
2023/02/13 07:11:47 [notice] 1#1: OS: Linux 5.4.0-137-generic
 +
2023/02/13 07:11:47 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
 +
2023/02/13 07:11:47 [notice] 1#1: start worker processes
 +
2023/02/13 07:11:47 [notice] 1#1: start worker process 29
 +
2023/02/13 07:11:47 [notice] 1#1: start worker process 30
 +
2023/02/13 07:11:47 [notice] 1#1: start worker process 31
 +
2023/02/13 07:11:47 [notice] 1#1: start worker process 32
 +
2023/02/13 07:11:47 [notice] 1#1: start worker process 33
 +
2023/02/13 07:11:47 [notice] 1#1: start worker process 34
 +
2023/02/13 07:11:47 [notice] 1#1: start worker process 35
 +
2023/02/13 07:11:47 [notice] 1#1: start worker process 36
 +
 
 +
== CPU- und Speicherauslastung ==
 +
 
 +
* '''docker stats'''
 +
 
 +
CONTAINER ID  NAME      CPU %    MEM USAGE / LIMIT    MEM %    NET I/O      BLOCK I/O        PIDS
 +
42f4afd9ad3d  nginx    0.00%    9.316MiB / 11.46GiB  0.08%    1.53kB / 0B  4.1kB / 8.19kB  9
 +
 
 +
* für bestimmte Container
 +
* '''docker stats nginx'''
 +
 
 +
CONTAINER ID  NAME      CPU %    MEM USAGE / LIMIT    MEM %    NET I/O      BLOCK I/O        PIDS
 +
42f4afd9ad3d  nginx    0.00%    9.316MiB / 11.46GiB  0.08%    1.53kB / 0B  4.1kB / 8.19kB  9
 +
 
 +
== Laufende Prozesse in einem Container ==
 +
 
 +
* '''docker top nginx'''
 +
 
 +
UID                PID                PPID                C                  STIME              TTY                TIME                CMD
 +
root                112223              112199              0                  07:11              ?                  00:00:00            nginx: master process nginx -g daemon off;
 +
systemd+            112291              112223              0                  07:11              ?                  00:00:00            nginx: worker process
 +
systemd+            112292              112223              0                  07:11              ?                  00:00:00            nginx: worker process
 +
systemd+            112293              112223              0                  07:11              ?                  00:00:00            nginx: worker process
 +
systemd+            112294              112223              0                  07:11              ?                  00:00:00            nginx: worker process
 +
systemd+            112295              112223              0                  07:11              ?                  00:00:00            nginx: worker process
 +
systemd+            112296              112223              0                  07:11              ?                  00:00:00            nginx: worker process
 +
systemd+            112297              112223              0                  07:11              ?                  00:00:00            nginx: worker process
 +
systemd+            112298              112223              0                  07:11              ?                  00:00:00            nginx: worker process
 +
 
 +
= Logging-Methoden =
 +
 
 +
* Die Logging-Methode kann durch die Auswahl eines anderen Logging-Treibers verändert werden
 +
* über '''docker run […] --log-driver ''log_driver''''' kann der Treiber eingestellt werden
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Treiber
 +
! Beschreibung
 +
|-
 +
| none
 +
| No logs are available for the container and docker logs does not return any output.
 +
|-
 +
| local
 +
| Logs are stored in a custom format designed for minimal overhead.
 +
|-
 +
| json-file
 +
| The logs are formatted as JSON. The default logging driver for Docker.
 +
|-
 +
| syslog
 +
| Writes logging messages to the syslog facility. The syslog daemon must be running on the host machine.
 +
|-
 +
| journald
 +
| Writes log messages to journald. The journald daemon must be running on the host machine.
 +
|-
 +
| gelf
 +
| Writes log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash.
 +
|-
 +
| fluentd
 +
| Writes log messages to fluentd (forward input). The fluentd daemon must be running on the host machine.
 +
|-
 +
| awslogs
 +
| Writes log messages to Amazon CloudWatch Logs.
 +
|-
 +
| splunk
 +
| Writes log messages to splunk using the HTTP Event Collector.
 +
|-
 +
| etwlogs
 +
| Writes log messages as Event Tracing for Windows (ETW) events. Only available on Windows platforms.
 +
|-
 +
| gcplogs
 +
| Writes log messages to Google Cloud Platform (GCP) Logging.
 +
|-
 +
| logentries
 +
| Writes log messages to Rapid7 Logentries.
 +
|}
 +
 
 +
= Links =
 +
 
 +
* https://docs.docker.com/config/containers/logging/configure/#supported-logging-drivers

Aktuelle Version vom 6. März 2023, 14:52 Uhr

Syntax

  • Für einen Container
  • docker logs [OPTIONS] NAME
  • Für Services/Tasks eines Docker-Swarms
  • docker service logs [OPTIONS] NAME
  • Normalerweise werden Standard Output und Standard Error dem Docker-log übergeben.

Beispiele

Containerprotokolle anzeigen

  • docker logs nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/02/13 07:11:47 [notice] 1#1: using the "epoll" event method
2023/02/13 07:11:47 [notice] 1#1: nginx/1.23.3
2023/02/13 07:11:47 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
2023/02/13 07:11:47 [notice] 1#1: OS: Linux 5.4.0-137-generic
2023/02/13 07:11:47 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/02/13 07:11:47 [notice] 1#1: start worker processes
2023/02/13 07:11:47 [notice] 1#1: start worker process 29
2023/02/13 07:11:47 [notice] 1#1: start worker process 30
2023/02/13 07:11:47 [notice] 1#1: start worker process 31
2023/02/13 07:11:47 [notice] 1#1: start worker process 32
2023/02/13 07:11:47 [notice] 1#1: start worker process 33
2023/02/13 07:11:47 [notice] 1#1: start worker process 34
2023/02/13 07:11:47 [notice] 1#1: start worker process 35
2023/02/13 07:11:47 [notice] 1#1: start worker process 36

neu einkommende Protokolleinträge anzeigen

  • docker logs -f nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/02/13 07:11:47 [notice] 1#1: using the "epoll" event method
2023/02/13 07:11:47 [notice] 1#1: nginx/1.23.3
2023/02/13 07:11:47 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
2023/02/13 07:11:47 [notice] 1#1: OS: Linux 5.4.0-137-generic
2023/02/13 07:11:47 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/02/13 07:11:47 [notice] 1#1: start worker processes
2023/02/13 07:11:47 [notice] 1#1: start worker process 29
2023/02/13 07:11:47 [notice] 1#1: start worker process 30
2023/02/13 07:11:47 [notice] 1#1: start worker process 31
2023/02/13 07:11:47 [notice] 1#1: start worker process 32
2023/02/13 07:11:47 [notice] 1#1: start worker process 33
2023/02/13 07:11:47 [notice] 1#1: start worker process 34
2023/02/13 07:11:47 [notice] 1#1: start worker process 35
2023/02/13 07:11:47 [notice] 1#1: start worker process 36

CPU- und Speicherauslastung

  • docker stats
CONTAINER ID   NAME      CPU %     MEM USAGE / LIMIT     MEM %     NET I/O       BLOCK I/O        PIDS
42f4afd9ad3d   nginx     0.00%     9.316MiB / 11.46GiB   0.08%     1.53kB / 0B   4.1kB / 8.19kB   9
  • für bestimmte Container
  • docker stats nginx
CONTAINER ID   NAME      CPU %     MEM USAGE / LIMIT     MEM %     NET I/O       BLOCK I/O        PIDS
42f4afd9ad3d   nginx     0.00%     9.316MiB / 11.46GiB   0.08%     1.53kB / 0B   4.1kB / 8.19kB   9

Laufende Prozesse in einem Container

  • docker top nginx
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                112223              112199              0                   07:11               ?                   00:00:00            nginx: master process nginx -g daemon off;
systemd+            112291              112223              0                   07:11               ?                   00:00:00            nginx: worker process
systemd+            112292              112223              0                   07:11               ?                   00:00:00            nginx: worker process
systemd+            112293              112223              0                   07:11               ?                   00:00:00            nginx: worker process
systemd+            112294              112223              0                   07:11               ?                   00:00:00            nginx: worker process
systemd+            112295              112223              0                   07:11               ?                   00:00:00            nginx: worker process
systemd+            112296              112223              0                   07:11               ?                   00:00:00            nginx: worker process
systemd+            112297              112223              0                   07:11               ?                   00:00:00            nginx: worker process
systemd+            112298              112223              0                   07:11               ?                   00:00:00            nginx: worker process

Logging-Methoden

  • Die Logging-Methode kann durch die Auswahl eines anderen Logging-Treibers verändert werden
  • über docker run […] --log-driver log_driver kann der Treiber eingestellt werden
Treiber Beschreibung
none No logs are available for the container and docker logs does not return any output.
local Logs are stored in a custom format designed for minimal overhead.
json-file The logs are formatted as JSON. The default logging driver for Docker.
syslog Writes logging messages to the syslog facility. The syslog daemon must be running on the host machine.
journald Writes log messages to journald. The journald daemon must be running on the host machine.
gelf Writes log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash.
fluentd Writes log messages to fluentd (forward input). The fluentd daemon must be running on the host machine.
awslogs Writes log messages to Amazon CloudWatch Logs.
splunk Writes log messages to splunk using the HTTP Event Collector.
etwlogs Writes log messages as Event Tracing for Windows (ETW) events. Only available on Windows platforms.
gcplogs Writes log messages to Google Cloud Platform (GCP) Logging.
logentries Writes log messages to Rapid7 Logentries.

Links