docker logs 查看日志(Docker logs view logs)

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/229

一、格式说明

docker logs [OPTIONS] CONTAINER

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:37) or relative (e.g. 42m for 42 minutes)
      --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:37) or relative (e.g. 42m for 42 minutes)
[root@iz8vb6yk5a7gzhaw7901zdz ~]# 

二、参数说明

-f : 查看实时日志,和tail -f的原理颇为相似
--since :显示某个开始时间的所有日志
-t : 显示时间戳
--tail :仅列出最新N条容器日志,--tail=10 : 查看最后的10条日志

三、常见用法

3.1 查看docker容器(nginx)的所有log

#其中nginx是容器名称,也可以是容器id,比如: docker logs -f 8d7b1800e1df
docker logs nginx

3.2 实时查看docker容器(nginx)的日志

docker logs -f nginx

3.3 查看docker容器(nginx)从2022年01月14日后的最新10条日志

docker logs -f -t --since="2022-01-14" --tail=10 nginx

3.4 导出docker容器(nginx)日志

docker logs nginx > nginx.log

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/229

————————

This article is an original article of Joshua 317. Please note that it is reproduced from Joshua 317 blog https://www.joshua317.com/article/229

1、 Format description

docker logs [OPTIONS] CONTAINER

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:37) or relative (e.g. 42m for 42 minutes)
      --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:37) or relative (e.g. 42m for 42 minutes)
[root@iz8vb6yk5a7gzhaw7901zdz ~]# 

2、 Parameter description

-f : 查看实时日志,和tail -f的原理颇为相似
--since :显示某个开始时间的所有日志
-t : 显示时间戳
--tail :仅列出最新N条容器日志,--tail=10 : 查看最后的10条日志

3、 Common usage

3.1 查看docker容器(nginx)的所有log

#其中nginx是容器名称,也可以是容器id,比如: docker logs -f 8d7b1800e1df
docker logs nginx

3.2 view the log of docker container (nginx) in real time

docker logs -f nginx

3.3 view the latest 10 logs of docker container (nginx) since January 14, 2022

docker logs -f -t --since="2022-01-14" --tail=10 nginx

3.4 导出docker容器(nginx)日志

docker logs nginx > nginx.log

This article is an original article of Joshua 317. Please note that it is reproduced from Joshua 317 blog https://www.joshua317.com/article/229