Get the App
SLTechnology News&Howtos  ›  Database  › 

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

Shulou Source: shulou.com Published: 2022-05-31 11:14:29 09月29日 Update

This article mainly explains "how to use the logs command in docker to display the last few lines". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to display the last few lines with the logs command in docker.

In docker, you can use the "--tail" parameter of the logs command to display the last lines of logs, the logs command to get the container logs, and the "--tail" parameter to set to list only the latest container logs with the syntax of "docker logs-- tail= rows".

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

How does the logs command display the last few lines in docker

Docker logs: get the log of the container

Grammar

Docker logs [OPTIONS] CONTAINER

OPTIONS description:

-f: trace log output

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

-t: displays the timestamp

-- tail: only the latest N container logs are listed

Example

Trace and view the log output of the container mynginx.

Runoob@runoob:~$ docker logs-f mynginx192.168.239.1-- [10/Jul/2016:16:53:33 + 0000] "GET / HTTP/1.1" 200612 "-" Mozilla/5.0 (Windows NT WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36 ""-"16:53:33 on 2016-07-10 [error] 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 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" 3040 "-"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36"-".

Check the latest 10 logs of container mynginx since July 1, 2016.

Docker logs-- since= "2016-07-01"-- tail=10 mynginx here, I believe you have a better understanding of "how to use the logs command in docker to display the last few lines". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Logs commands containers content parameters time syntax learning tracking output practicality deeper interest examples practicality practicality simplicity of operation tutorials methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi MariaDB macOS Redmi