Docker日志管理(十一)--技术流ken

 

Docker logs

 

对于一个运行的容器,Docker 会将日志发送到 容器的 标准输出设备(STDOUT)和标准错误设备(STDERR),STDOUT 和 STDERR 实际上就是容器的控制台终端。

举个例子,用下面的命令运行 httpd 容器:

复制代码
[root@host1 ~]# docker run -p 80:80 httpd Unable to find image 'httpd:latest' locally latest: Pulling from library/httpd 5e6ec7f28fb7: Pull complete  566e675a8212: Pull complete  ef5a8026039b: Pull complete  22ecb0106557: Pull complete  91cc511c603e: Pull complete  Digest: sha256:44daa8e932a32ab6e50636d769ca9a60ad412124653707e5ed59c0209c72f9b3 Status: Downloaded newer image for httpd:latest AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.12. Set the 'ServerName' directive globally to suppress this messageAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.12. Set the 'ServerName' directive globally to suppress this message[Mon Jan 28 08:55:25.168252 2019] [mpm_event:notice] [pid 1:tid 140652308325568] AH00489: Apache/2.4.38 (Unix) configured -- resuming normal operations [Mon Jan 28 08:55:25.182578 2019] [core:notice] [pid 1:tid 140652308325568] AH00094: Command line: 'httpd -D FOREGROUND'
复制代码

 

因为我们在启动日志的时候没有用-d 参数,httpd 容器以前台方式启动,日志会直接打印在当前的终端窗口。

如果加上-d 参数以后台方式运行容器,我们就看不到输出的日志了。

复制代码
[root@host1 ~]# docker run -d -p 80:80 httpd 98d1fe5f1d074c345f578ef7767e8b2543977e61bb241f5629509c54502a7218
复制代码

 

这种情况下,查看容器日志推荐的方法是用docker logs命令。

复制代码
[root@host1 ~]# docker logs -f 98d1fe5f1d07   AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.12. Set the 'ServerName' directive globally to suppress this messageAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.12. Set the 'ServerName' directive globally to suppress this message[Mon Jan 28 08:56:09.352502 2019] [mpm_event:notice] [pid 1:tid 139863955322048] AH00489: Apache/
                        
关键字:
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

联系我们

电话咨询

0532-85025005

扫码添加微信