当前位置: 首页 > 知识库问答 >
问题:

如何用Docker配置fluentd?

经嘉
2023-03-14

我现在正在使用rails应用程序。在我的应用程序配置文件中,我添加了以下内容:

config/application.rb

logger = Fluent::Logger::FluentLogger.new(nil, host: '127.0.0.1', port: '24224')
$ docker-compose up

...
sidekiq_1 | E, [2015-11-09T02:45:44.857664 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
sidekiq_1 | E, [2015-11-09T02:45:44.860403 #1] ERROR -- : Connection will be retried.
sidekiq_1 | E, [2015-11-09T02:45:44.862926 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
sidekiq_1 | E, [2015-11-09T02:45:44.864514 #1] ERROR -- : Connection will be retried.
web_1     | E, [2015-11-09T02:45:48.512481 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
web_1     | E, [2015-11-09T02:45:48.512785 #1] ERROR -- : Connection will be retried.
web_1     | E, [2015-11-09T02:45:48.515245 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
web_1     | E, [2015-11-09T02:45:48.515571 #1] ERROR -- : Connection will be retried.
...
$ docker-machine ip myapp
=> 192.168.99.100
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
b5e980e1aa61        myapp_web         "bundle exec rails s "   About an hour ago   Up 6 minutes        0.0.0.0:3000->3000/tcp   myapp_web_1
43365dfb403f        myapp_sidekiq     "bundle exec sidekiq "   About an hour ago   Up 6 minutes                                 myapp_sidekiq_1
9570ee727f04        mysql               "/entrypoint.sh mysql"   About an hour ago   Up 6 minutes        0.0.0.0:3306->3306/tcp   myapp_db_1
e24495920c58        redis               "/entrypoint.sh redis"   2 days ago          Up 6 minutes        0.0.0.0:6379->6379/tcp   myapp_redis_1

为什么未能连接fluentd关于sidekiq和web图像?

将其添加到DockerFile:

RUN mkdir -p /fluentd/etc

将其添加到docker-compose.yml:

fluentd:
  image: fluent/fluentd:latest
  ports:
    - "24224:24224"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: reading config file path="/fluentd/etc/fluent.conf"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: starting fluentd-0.12.16
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: gem 'fluentd' version '0.12.16'
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: adding match in @mainstream pattern="docker.**" type="file"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: adding match in @mainstream pattern="**" type="file"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: adding filter pattern="**" type="stdout"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: adding source type="forward"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: using configuration file: <ROOT>
fluentd_1 |   <source>
fluentd_1 |     @type forward
fluentd_1 |     @id input1
fluentd_1 |     @label @mainstream
fluentd_1 |     port 24224
fluentd_1 |   </source>
fluentd_1 |   <filter **>
fluentd_1 |     @type stdout
fluentd_1 |   </filter>
fluentd_1 |   <label @mainstream>
fluentd_1 |     <match docker.**>
fluentd_1 |       @type file
fluentd_1 |       @id output_docker1
fluentd_1 |       path /fluentd/log/docker.*.log
fluentd_1 |       symlink_path /fluentd/log/docker.log
fluentd_1 |       append true
fluentd_1 |       time_slice_format %Y%m%d
fluentd_1 |       time_slice_wait 1m
fluentd_1 |       time_format %Y%m%dT%H%M%S%z
fluentd_1 |       buffer_path /fluentd/log/docker.*.log
fluentd_1 |     </match>
fluentd_1 |     <match **>
fluentd_1 |       @type file
fluentd_1 |       @id output1
fluentd_1 |       path /fluentd/log/data.*.log
fluentd_1 |       symlink_path /fluentd/log/data.log
fluentd_1 |       append true
fluentd_1 |       time_slice_format %Y%m%d
fluentd_1 |       time_slice_wait 10m
fluentd_1 |       time_format %Y%m%dT%H%M%S%z
fluentd_1 |       buffer_path /fluentd/log/data.*.log
fluentd_1 |     </match>
fluentd_1 |   </label>
fluentd_1 | </ROOT>
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: listening fluent socket on 0.0.0.0:24224
sidekiq_1 | E, [2015-11-09T09:51:11.887833 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
sidekiq_1 | E, [2015-11-09T09:51:11.888508 #1] ERROR -- : Connection will be retried.
sidekiq_1 | E, [2015-11-09T09:51:11.893544 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
sidekiq_1 | E, [2015-11-09T09:51:11.893926 #1] ERROR -- : Connection will be retried.

共有1个答案

戎洛华
2023-03-14

确保您的docker-compose.yml有一个fluentd节(就像这个节一样),至少公开了端口24224(除非您想从主机直接访问它,否则没有top map)

答案原文(2015)

那么您的raildocker-compose.ymlsidekiq部分应该有一个链接部分:

links:
  - fluentd
depends_on:
  - fluentd

请参见“docker_compose.yml链接depends_on之间的差异”。
示例:“如何使用Dockerfile将主容器链接到db容器?”。

 类似资料:
  • 本文向大家介绍如何配置docker官方源并用yum安装docker,包括了如何配置docker官方源并用yum安装docker的使用技巧和注意事项,需要的朋友参考一下 本文介绍了如何配置docker官方源并用yum安装docker ,分享给大家,希望对各位有帮助 一、docker的官方安装文档: https://docs.docker.com/engine/installation/linux/c

  • 这节课让我们来容器化Flask应用吧...... 首先你需要确保你的环境中已经安装了Docker和Docker Compose: $ docker -v Docker version 17.05.0-ce, build 89658be $ docker-compose -v docker-compose version 1.14.0, build unknown 在项目的根目录下面创建一个Doc

  • 我在Windows 10上安装了Docker,并从Docker Hub中提取了jenkins Docker。接下来,我开始了我的jenkins docker, 接下来,我使用Manage Jenkins和Manage Plugins安装Docker plugin,然后转到配置页面并尝试添加Docker Cloud。 在我进入 Docker 主机 URI : tcp://127.0.0.1:2375

  • 问题内容: 我有一个小的Spring Boot Web应用程序,可将数据保存到Redis。 运行docker-compose.yml容器后,但我已启动“连接已重置”。 spring引导aplication.yml docker-compose.yml 如何链接Spring Boot和Redis? 我错过了什么? 问题答案: 是错误的地址。使用的主机名。

  • 但是,我需要它从我们的nexus服务中提取:。在docker-compose文件中,我已经使用了正确的nexus图像路径。(通过用docker-compose手动启动它来验证。然而,TestContainers也会拉入docker-compose文件之外的其他图像。正是这些图像导致了失败。 我很高兴Docker Desktop或TestContainers的配置更改能解决这个问题。 注意:我已经尝

  • 问题内容: 我正在设置docker镜像,以将Vue应用作为静态文件提供。我的vue应用程序使用Vue- Router,并且可以在其他服务器上完美运行。我的Nginx配置如下所示:https : //router.vuejs.org/guide/essentials/history-mode.html#example-server- configurations 现在我想迁移到docker,这是我的