查看docker logs 帮助信息
[root@localhost ~]# 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 (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 # 日志显示用时间戳展示
[root@localhost ~]#
docker logs -f 容器
跟踪容器日志,主要用于查看程序报错或者排查故障使用
docker logs --since 10m 容器
显示最新10分钟的日志
[root@localhost ~]# docker logs --since=10m 171401662b68
192.168.100.83 - - [13/Oct/2017:11:08:22 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:23 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:23 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:24 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:24 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:24 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:25 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:25 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:26 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
[root@localhost ~]#
docker logs --since='2017-10-13' 容器
显示2017-10-13日期的日志
[root@localhost ~]# docker logs --since='2017-10-13' 171401662b68
172.18.0.1 - - [13/Oct/2017:09:38:48 +0800] "GET /psc/dict/allDict HTTP/1.1" 200 11080 "-" "curl/7.55.0"
192.168.100.83 - - [13/Oct/2017:10:50:57 +0800] "GET / HTTP/1.1" 200 108356 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:10:50:58 +0800] "GET /favicon.ico HTTP/1.1" 404 139 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:10:53:28 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:10:53:29 +0800] "GET /web/cms/favicon.ico HTTP/1.1" 404 138 "http://192.168.100.196:8083/web/cms/view" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:10:53:35 +0800] "GET / HTTP/1.1" 200 108349 "http://192.168.100.196:8083/web/cms/view" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:04:38 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:05:50 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:05:53 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
docker logs --tail=2 容器
显示最后几行日志
Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
[root@localhost ~]# docker logs --tail=2 171401662b68
192.168.100.83 - - [13/Oct/2017:11:08:25 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
192.168.100.83 - - [13/Oct/2017:11:08:26 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
[root@localhost ~]#
docker logs -t --tail=2 容器
显示日志的时间戳
[root@localhost ~]# docker logs -t --tail=2 171401662b68
2017-10-13T03:08:25.689222590Z 192.168.100.83 - - [13/Oct/2017:11:08:25 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
2017-10-13T03:08:26.147833583Z 192.168.100.83 - - [13/Oct/2017:11:08:26 +0800] "GET /web/cms/view HTTP/1.1" 200 15757 "http://192.168.100.196:8083/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.35"
[root@localhost ~]#
其他选项不太常用,没有深入研究