Home > Database > Mysql Tutorial > How to display the last few lines of logs command in docker

How to display the last few lines of logs command in docker

WBOY
Release: 2022-02-07 15:21:10
Original
13231 people have browsed it

In docker, you can use the "--tail" parameter of the logs command to display the last few lines of logs. The logs command is used to obtain the logs of the container. The "--tail" parameter is used to set only the latest lines to be listed. Several container logs, the syntax is "docker logs --tail=number of lines".

How to display the last few lines of logs command in docker

The operating environment of this tutorial: linux7.3 system, docker-1.13.1 version, Dell G3 computer.

How to display the last few lines of the logs command in docker

docker logs: Get the log of the container

Syntax

docker logs [OPTIONS] CONTAINER
Copy after login

OPTIONS description:

-f: Trace log output

--since: Display all logs at a certain start time

-t: Display timestamp

--tail: List only The latest N container logs

Instance

Trace and view the log output of the container mynginx.

runoob@runoob:~$ docker logs -f mynginx
192.168.239.1 - - [10/Jul/2016:16:53:33 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"
2016/07/10 16:53:33 [error] 5#5: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.239.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.239.130", referrer: "http://192.168.239.130/"
192.168.239.1 - - [10/Jul/2016:16:53:33 +0000] "GET /favicon.ico HTTP/1.1" 404 571 "http://192.168.239.130/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"
192.168.239.1 - - [10/Jul/2016:16:53:59 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"
...
Copy after login

View the latest 10 logs of the container mynginx from July 1, 2016.

docker logs --since="2016-07-01" --tail=10 mynginx
Copy after login

Recommended learning: "docker video tutorial"

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template