************************* docker问题记录 *******************

1.无法查看日志

[root@k8s-master04 harbor]# docker logs nginx
Error response from daemon: configured logging driver does not support reading
[root@k8s-master04 harbor]#

原因

Docker包括多种容器日志记录方式,这个机制又叫做logging drivers。logging driver经常在配置在Docker 守护进程级别,默认的logging driver是json-file. 还支持以下几种级别:

Driver Description
none No log output for the specific container is produced
json-file This is default driver. The logging information is stored in files, formatted as Json
journald If the journals daemon is running on the host machine, we can use this driver. It forwards logging to the journald daemon
syslogd If the syslog daemon is running on the host machine, we can configure this driver, which will forward the log messages to the syslgo daemon.
gelf When using the driver, log messages are written to a Graylog Extended Log Format(GELF) endpoint. Popular examples of such endpoints are Graylog and Logstash
fluentd Assuming that the fluentd daemon is installed on the host system, this driver wrties logs messages to it.

 

3.  在启动容器时,指定使用的logging driver 案例

(1) 运行busybox容器,且使用—log-driver参数去指定Logging driver的none.

[root@c720120 ~]# docker container run --name test -it \
> --log-driver none \
> busybox sh -c 'for N in 1 2 3; do echo "Hello $N"; done'
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
07a152489297: Pull complete
Digest: sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47
Status: Downloaded newer image for busybox:latest
Hello 1
Hello 2
Hello 3

(2)获取先前容器的日志

[root@c720120 ~]# docker container logs test
Error response from daemon: configured logging driver does not support reading

 制作基础alpine并安装基础软件包

更新指定安装源

vi etc/apk/repositories

http://mirrors.aliyun.com/alpine/v3.8/main/

http://mirrors.aliyun.com/alpine/v3.8/community/

apk update

安装vim

apk add vim

安装telnet

apk add busybox-extras

#用于文本方式查看网页,用于测试http协议
 
apk add curl  
 
#提供了查看网络连接的协议端口的命令ss,可以替代netstat命令
 
apk add iproute2  
 
#drill 命令可以替代dig和nslookup DNS查询命令
 
apk add drill  
 
重新制作image
docker commit -a 'xiaoyu61' -m 'init:v0.1' d6e46aa2470d alpine_init:v0.1
posted @ 2020-11-25 18:33  番茄土豆西红柿  阅读(0)  评论(0)    收藏  举报
TOP