名称¶
podman-logs - 显示一个或多个容器的日志
简介¶
podman logs [选项] 容器 [容器…]
podman container logs [选项] 容器 [容器…]
描述¶
podman logs 命令在执行时批量检索一个或多个容器中存在的日志。这不能保证与 podman run 结合使用时的执行顺序(即在执行 podman logs 时,run 可能还没有生成任何日志)。
选项¶
--color¶
以不同颜色输出容器日志。
--follow, -f¶
跟踪日志输出。默认为 false。
注意:当跟踪一个被 podman rm
删除或在退出时删除 (podman run --rm ...
) 的容器时,日志文件有可能在 podman logs
读取最终内容之前被删除。
--latest, -l¶
不提供名称或 ID,而是使用最新创建的容器。注意:最新创建的容器可能来自主机上 Podman 的其他用户。(此选项不适用于远程 Podman 客户端,包括 Mac 和 Windows(WSL2 除外)机器)
--names, -n¶
在日志中输出容器名称而不是容器 ID。
--since=时间戳¶
显示从 TIMESTAMP 开始的日志。--since 选项可以是 Unix 时间戳、日期格式的时间戳或 Go 持续时间字符串(例如 10m, 1h30m),相对于客户端机器的时间计算。支持的日期格式时间戳包括 RFC3339Nano、RFC3339、2006-01-02T15:04:05、2006-01-02T15:04:05.999999999、2006-01-02Z07:00 和 2006-01-02。
--tail=行数¶
输出日志末尾指定行数。LINES 必须是一个整数。默认为 -1,表示打印所有行。
--timestamps, -t¶
在日志输出中显示时间戳。默认为 false。
--until=时间戳¶
显示直到 TIMESTAMP 的日志。--until 选项可以是 Unix 时间戳、日期格式的时间戳或 Go 持续时间字符串(例如 10m, 1h30m),相对于客户端机器的时间计算。支持的日期格式时间戳包括 RFC3339Nano、RFC3339、2006-01-02T15:04:05、2006-01-02T15:04:05.999999999、2006-01-02Z07:00 和 2006-01-02。
示例¶
查看容器的日志
podman logs -t b3f2436bdb978c1d33b1387afb5d7ba7e3243ed2ce908db431ac0069da86cb45
2017/08/07 10:16:21 Seeked /var/log/crio/pods/eb296bd56fab164d4d3cc46e5776b54414af3bf543d138746b25832c816b933b/c49f49788da14f776b7aa93fb97a2a71f9912f4e5a3e30397fca7dfe0ee0367b.log - &{Offset:0 Whence:0}
1:C 07 Aug 14:10:09.055 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 07 Aug 14:10:09.055 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 07 Aug 14:10:09.055 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 07 Aug 14:10:09.055 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
1:M 07 Aug 14:10:09.055 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1:M 07 Aug 14:10:09.055 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
1:M 07 Aug 14:10:09.056 * Running mode=standalone, port=6379.
1:M 07 Aug 14:10:09.056 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 07 Aug 14:10:09.056 # Server initialized
仅查看容器日志的最后两行
podman logs --tail 2 b3f2436bdb97
# WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
# Server initialized
查看所有容器的日志
podman logs -t --since 0 myserver
1:M 07 Aug 14:10:09.055 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1:M 07 Aug 14:10:09.055 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
1:M 07 Aug 14:10:09.056 * Running mode=standalone, port=6379.
1:M 07 Aug 14:10:09.056 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 07 Aug 14:10:09.056 # Server initialized
查看容器自某个时间以来的日志
podman logs -t --since 2017-08-07T10:10:09.055837383-04:00 myserver
1:M 07 Aug 14:10:09.055 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1:M 07 Aug 14:10:09.055 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
1:M 07 Aug 14:10:09.056 * Running mode=standalone, port=6379.
1:M 07 Aug 14:10:09.056 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 07 Aug 14:10:09.056 # Server initialized
查看容器过去 10 分钟内生成的日志
podman logs --since 10m myserver
# Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
# Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit, Increase 'ulimit -n' when higher maxclients are required.
查看容器直到 30 分钟前的日志
podman logs --until 30m myserver
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.0.2.100. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.0.2.100. Set the 'ServerName' directive globally to suppress this message
[Tue Jul 20 13:18:14.223727 2021] [mpm_event:notice] [pid 1:tid 140021067187328] AH00489: Apache/2.4.48 (Unix) configured -- resuming normal operations
[Tue Jul 20 13:18:14.223819 2021] [core:notice] [pid 1:tid 140021067187328] AH00094: Command line: 'httpd -D FOREGROUND'
另请参阅¶
历史¶
2018 年 2 月,Brent Baude bbaude@redhat.com 更新
2017 年 8 月,最初由 Ryan Cole rycole@redhat.com 编译