Docker container log view

1. Container log view command

Usage:  docker logs [OPTIONS] CONTAINER

Fetch the logs of a container

Options:
      --details        Show extra details provided to logs
  -f, --follow         Follow log output
      --since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
  -n, --tail string    Number of lines to show from the end of the logs (default "all")
  -t, --timestamps     Show timestamps
      --until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)

2. Usage scenarios of command parameters

1) View container logs according to start time and end time

For example, to view the log information of the influxdb container from the last 20 minutes to the last 10 minutes, the command is as follows:

docker logs --since="20m" --until="10m" influxdb

[Description]: –since passes in the start time, –until passes in the end time.

2) Use UTC format time to view container logs

For example, to view the log information of the influxdb container since 2022-10-10T02:31:00Z, the command is as follows:

docker logs --since="2022-10-10T02:31:00Z" influxdb

3) Display the timestamp of the log

For example, to view the log information ( display timestamp ) of the influxdb container from the last 20 minutes to the last 10 minutes , the command is as follows:

docker logs --since="20m" --until="10m" -t influxdb

[Description]: The -t or –timestamps parameter is used to display the timestamp.

4) View the log of the last n lines

For example, to view the last 100 lines of log information ( displaying timestamps ) of the influxdb container from the last 20 minutes to the last 10 minutes , the command is as follows:

docker logs --since="20m" --until="10m" -t --tail 100 influxdb

or

docker logs --since="20m" --until="10m" -t -n100 influxdb

[Explanation]: –tail 100 or -n100 means the last 100 lines.

5) Trace log output

For example, to view the real-time log information (time stamp displayed) of the influxdb container after the last 20 minutes, the command is as follows:

docker logs -f --since="20m" -t  influxdb5

[Description]: -f or –follow means trace log output.


Guess you like

Origin blog.csdn.net/aikudexiaohai/article/details/130103644