我尝试使用
nginx
docker 日志驱动程序为基于前端 fluentd
的容器记录一些日志,但失败了。
我最终对
fluentd
进行了以下配置(位于 /tmp/fluentd/fluent.conf
):
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<match **-**>
@type stdout
</match>
以及以下 docker swarm 清单:
version: '3.8'
networks:
base:
services:
fluentd:
image: fluent/fluentd:v1.17.0-1.0
volumes:
- /tmp/fluentd:/fluentd/etc
ports:
- 24224:24224
networks:
- base
test-curl:
image: alpine
command: sh -c "apk add curl && while true; do curl fluentd:24224; sleep 5; done"
depends_on:
- fluentd
networks:
- base
test-service:
image: nginx:1.25
depends_on:
- fluentd
logging:
driver: fluentd
options:
# fluentd-address: host.docker.internal:24224 # this line routes queries via docker host
fluentd-address: fluentd:24224 # this line tries to send logs directly to fluentd container
tag: something
networks:
- base
此配置运行
fluentd
服务和两个测试服务。首先(使用基于 alpine
的卷曲测试)效果很好。其次,使用 fluentd
驱动程序,则不会。它无法启动并显示以下消息:
> docker service ps fluentd-test_test-service --no-trunc
...
<...> \_ fluentd-test_test-service.1 nginx:1.25@sha256:<...> docker-desktop Shutdown Failed 22 seconds ago "starting container failed: failed to create task for container: failed to initialize logging driver: dial tcp: lookup fluentd: i/o timeout"
...
看起来由于某种原因它无法在同一网络中看到
fluentd
容器。
但是,当我用 host.docker.internal
地址注释掉标记行并取消注释行时,一切都会按预期进行。
在 WSL2(2.1.5.0,内核 5.15.146.1-2)、Docker 26.1.1、Windows 10.0.19045.4412 下运行
我尝试过的:
docker
wsl
fluent/fluentd
fluentd
(开放端口、可访问性、DNS 解析 - 工作正常)请,任何想法将不胜感激。
看起来所需的行为无法通过
fluentd
驱动程序实现,正如文档中所写:
将日志消息写入fluentd
(转发输入)。fluentd
守护进程必须在主机上运行。fluentd
https://docs.docker.com/config/containers/logging/configure/#supported-logging-drivers