docker - 常用命令 - 查看日志

官方资料

docker logs

使用

1
$ docker logs [OPTIONS] CONTAINER

Options

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

示例

  • docker logs 命令,可以跟踪容器的日志并且输出日志的时间

    1
    docker logs -f -t busybox
  • 写入指定容器在某时间段的日志

    1
    docker logs --since="2022-09-19T01:00:00" --until "2022-09-21T09:40:00" busybox  &>file.txt
  • 将最近1分钟的日志写到file.txt文件

    1
    docker logs --since 50m busybox  &>file.txt
  • 查看实时日志,仅仅显示最新的100条日志数据

    1
    docker logs -f -t --tail 100 busybox  &>file.txt
-------------本文结束感谢您的阅读-------------