docker logs : 获取容器的日志
语法
docker logs [options] container
options说明:
-
-f : 跟踪日志输出
-
--since :显示某个开始时间的所有日志
-
-t : 显示时间戳
-
--tail :仅列出最新n条容器日志
实例
跟踪查看容器mynginx的日志输出。
coonote@coonote:~$ docker logs -f mynginx 192.168.239.1 - - [10/jul/2016:16:53:33 0000] "get / http/1.1" 200 612 "-" "mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/45.0.2454.93 safari/537.36" "-" 2016/07/10 16:53:33 [error] 5#5: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: no such file or directory), client: 192.168.239.1, server: localhost, request: "get /favicon.ico http/1.1", host: "192.168.239.130", referrer: "http://192.168.239.130/" 192.168.239.1 - - [10/jul/2016:16:53:33 0000] "get /favicon.ico http/1.1" 404 571 "http://192.168.239.130/" "mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/45.0.2454.93 safari/537.36" "-" 192.168.239.1 - - [10/jul/2016:16:53:59 0000] "get / http/1.1" 304 0 "-" "mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/45.0.2454.93 safari/537.36" "-" ...
查看容器mynginx从2016年7月1日后的最新10条日志。
docker logs --since="2016-07-01" --tail=10 mynginx