docker - 流利的Docker无法从我的日志文件中消失

标签 docker logging kubernetes elastic-stack fluentd

Docker中的Fluentd无法从我的日志文件中删除
我在/var/log/logf/a.log中的输入:

test 1st log
test 2nd log
test 3rd log
和我的配置/opt/app/conf/fluent.conf:
<source>
   @type tail
   path /var/log/logf/a.log
   tag test
   read_from_head true
   <parse>
      @type none
      message_key test
   </parse>
</source>

<match test>
   @type stdout
</match>
和我的Dockerfile id /opt/app/Dockerfile
FROM fluent/fluentd:v1.11-debian-1
USER root

COPY ./conf/fluent.conf /fluentd/etc
RUN ["gem", "install", "fluent-plugin-elasticsearch", "--no-document", "--version", "3.5.2"]
USER fluent
我运行我的Dockerfile
$ sudo docker build -t log-app .
$ sudo docker run -d --name logging log-app:latest
$ sudo docker logs -f logging
结果卡住了,我不知道为什么
2020-10-26 10:24:58 +0000 [info]: parsing config file is succeeded path="/fluentd/etc/fluent.conf"
2020-10-26 10:24:58 +0000 [info]: gem 'fluent-plugin-elasticsearch' version '3.5.2'
2020-10-26 10:24:58 +0000 [info]: gem 'fluentd' version '1.11.4'
2020-10-26 10:24:58 +0000 [warn]: 'pos_file PATH' parameter is not set to a 'tail' source.
2020-10-26 10:24:58 +0000 [warn]: this parameter is highly recommended to save the position to resume tailing.
2020-10-26 10:24:58 +0000 [info]: using configuration file: <ROOT>
 <source>
   @type tail
   path "/var/log/logf/a.log"
   tag "test"
   read_from_head true
   <parse>
      @type "none"
      message_key "test"
      unmatched_lines
   </parse>
 </source>
 <match test>
    @type stdout
 </match>
</ROOT>
2020-10-26 10:24:58 +0000 [info]: starting fluentd-1.11.4 pid=6 ruby="2.6.6"
2020-10-26 10:24:58 +0000 [info]: spawn command to main:  cmdline=["/usr/local/bin/ruby", "-Eascii- 8bit:ascii-8bit", "/usr/local/bundle/bin/fluentd", "-c", "/fluentd/etc/fluent.conf", "-p", "/fluentd/plugins", "--under-supervisor"]
2020-10-26 10:24:59 +0000 [info]: adding match pattern="test" type="stdout"
2020-10-26 10:24:59 +0000 [info]: adding source type="tail"
2020-10-26 10:24:59 +0000 [warn]: #0 'pos_file PATH' parameter is not set to a 'tail' source.
2020-10-26 10:24:59 +0000 [warn]: #0 this parameter is highly recommended to save the position to resume tailing.
2020-10-26 10:24:59 +0000 [info]: #0 starting fluentd worker pid=15 ppid=6 worker=0
2020-10-26 10:24:59 +0000 [info]: #0 fluentd worker is now running worker=0
我认为这是一个权限问题,但是我不确定,因为此Fluentd不会引发错误,您能解决这个问题吗?

[已解决] 由karan shah先生的解释完全解决了
我用docker-compose和安装量解决了以下问题:
在文件/opt/app/docker-compose.yaml
version: '2'

services:
  fluentd:
    build: .
    container_name: fl-logging
    volumes:
      - "./conf/:/fluentd/etc:ro"
      - "/var/log/logf:/var/log/logf"
并运行docker compose
 $ sudo docker-compose up -d --build

最佳答案

问题是您尚未将本地日志文件安装到Fluentd容器中以使其可访问。
使用如下命令。sudo docker run -d --name logging -v PATHTOYOURLOGFILE:/var/log/logf/ log-app:latest阅读有关here卷的更多信息。
您还可以使用如下所示的docker-compose文件

version: '2.2'
services:
 fluentd:
    build: ./opt/app/
    container_name: fl01
    volumes:
      - "/opt/app/conf/:/fluentd/etc/:ro"
      - "PATHTOYOURLOGFILE:/var/log/logf/"
    networks:
      - elastic
    ports:
      - "9880:9880"
networks:
  elastic:
    driver: bridge

关于docker - 流利的Docker无法从我的日志文件中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64535572/

相关文章:

elasticsearch - Kubernetes 日志在 kibana 中拆分

database - 配置Unifi Controller以使用外部MongoDB数据库-可能出现角色问题?

java - 通过全局配置文件配置 Logger

docker - 在 docker 容器中挂载外部卷

java - 如何防止logback/slf4j解析换行符

c# - 支持从 VSTO 加载项进行日志记录的最简单方法

kubernetes - 如何在 dnsConfig 中将节点 ip 设置为名称服务器?

kubernetes - k8s : Communicating between pods of same deployment

docker - 如何在应用容器启动之前将插件安装到应用的文件系统?

docker - 无法调试在 docker 容器中运行的 TestCafe 浏览器