docker logs

更新时间:
2023-03-29
下载文档

docker logs

查看容器日志信息。

命令格式

docker logs [option] [containerId|containerName]

参数说明

参数说明是否必填
option查看选项,常用参数如下:
-f:设置过滤条件
--tail:设置查看最新日志的条数
containerID容器 IDcontainerID 和 containerName 至少需要填一个
containerName容器名称containerID 和 containerName 至少需要填一个

命令示例

  • 示例一:根据容器名称查看最近 10 条日志信息。如容器名称为 nginx-server。

    docker logs -f --tail=10 nginx
    
    2023/03/29 06:36:35 [notice] 1#1: using the "epoll" event method
    2023/03/29 06:36:35 [notice] 1#1: nginx/1.21.6
    2023/03/29 06:36:35 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
    2023/03/29 06:36:35 [notice] 1#1: OS: Linux 3.10.0-1160.el7.x86_64
    2023/03/29 06:36:35 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
    2023/03/29 06:36:35 [notice] 1#1: start worker processes
    2023/03/29 06:36:35 [notice] 1#1: start worker process 24
    2023/03/29 06:36:35 [notice] 1#1: start worker process 25
    2023/03/29 06:36:35 [notice] 1#1: start worker process 26
    2023/03/29 06:36:35 [notice] 1#1: start worker process 27
    
  • 示例二:根据容器 ID 查看最近 10 条日志信息。如容器 ID 为 8b291424877a。

    docker logs -f --tail=10 8b291424877a
    
    2023/03/29 06:36:35 [notice] 1#1: using the "epoll" event method
    2023/03/29 06:36:35 [notice] 1#1: nginx/1.21.6
    2023/03/29 06:36:35 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
    2023/03/29 06:36:35 [notice] 1#1: OS: Linux 3.10.0-1160.el7.x86_64
    2023/03/29 06:36:35 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
    2023/03/29 06:36:35 [notice] 1#1: start worker processes
    2023/03/29 06:36:35 [notice] 1#1: start worker process 24
    2023/03/29 06:36:35 [notice] 1#1: start worker process 25
    2023/03/29 06:36:35 [notice] 1#1: start worker process 26
    2023/03/29 06:36:35 [notice] 1#1: start worker process 27
    
    
文档内容是否对您有所帮助?
有帮助
没帮助