Home  >  Article  >  Operation and Maintenance  >  How to view the last few lines of logs in docker

How to view the last few lines of logs in docker

藏色散人
藏色散人Original
2021-12-13 13:56:0312402browse

How to view the last few lines of docker logs: 1. Open the command window; 2. Dynamically view the last 100 lines of the log through the "docker logs -f -t --tail=100 c337e9df72a7" command.

How to view the last few lines of logs in docker

The operating environment of this article: ubuntu 18.04 system, Docker version 20.10.11, Dell G3 computer.

How to view the last few lines of logs in docker?

docker dynamically view the last 100 lines of the log:

docker logs -f -t --tail=100 c337e9df72a7

refers to the real-time view of the last 100 lines of the log with the container ID c337e9df72a7

How to view the last few lines of logs in docker

$ docker logs [OPTIONS] CONTAINER
  Options:
        --details        显示更多的信息
    -f, --follow         跟踪实时日志
        --since string   显示自某个timestamp之后的日志,或相对时间,如42m(即42分钟)
        --tail string    从日志末尾显示多少行日志, 默认是all
    -t, --timestamps     显示时间戳
        --until string   显示自某个timestamp之前的日志,或相对时间,如42m(即42分钟)

Example:

View the log after the specified time, only display the last 100 lines:

$ docker logs -f -t --since="2018-02-08" --tail=100 CONTAINER_ID

View the log for the last 30 minutes:

$ docker logs --since 30m CONTAINER_ID

View logs after a certain time:

$ docker logs -t --since="2018-02-08T13:23:37" CONTAINER_ID

View logs during a certain time period:

$ docker logs -t --since="2018-02-08T13:23:37" --until "2018-02-09T12:23:37" CONTAINER_ID

Recommended learning: "Docker Video Tutorial"

The above is the detailed content of How to view the last few lines of logs in docker. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn