在实际使用docker的过程中,我们经常需要查看一个docker内部的日志来查看程序是否正常运行以及排查错误等,所以对于docker容器如何来查看日志是一项非常基本且重要的事情。
docker logs --help
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
Options:
--details Show extra details provided to logs
-f, --follow Follow log output
--help Print usage
--since string Show logs since timestamp
--tail string Number of lines to show from the end of the logs (default "al
-t, --timestamps Show timestamps
这上面展示的就是常用的参数:
- –details 显示额外的信息
- -f或者–follow显示实时信息
- –since 加上时间戳查找特定时间的日志
- –tail 加上整数查看最新多少行的日志
- -t或者–timestamps 表示显示时间戳
示例的命令如下:
docker logs -f -t --since="2020-02-03" --tail=10 mqtt_mqtt_1
上面就是查看容器mqtt_mqtt_1从2020年2月3号开始最新10行的日志.