【问题标题】:How to start nodejs and filebeat in same contianer如何在同一个容器中启动节点 js 和 filebeat
【发布时间】:2022-06-21 15:51:07
【问题描述】:

我需要在同一个容器中创建一个带有 nodejs 应用程序和 filebeat 的 docker 容器。所以filebeat会将nodejs日志中继到我的logstash服务器。我已经创建了 docker 文件,当我构建图像时,它运行时没有错误。但是当我进入容器并看到没有创建与 filebeat 相关的文件时。 NodeJS 应用程序按预期运行,但 filebeat 根本不工作。

我使用了这里提到的filebeathttps://www.elastic.co/guide/en/beats/filebeat/current/running-on-docker.html给出的自定义文件

那么我们可以在同一个容器中运行 nodeJS 应用程序和 filebeat 吗?如果是的话,我做错了什么?

这是我的 docker 文件 ---


# Test web app that returns the name of the host/pod/container servicing req
# Linux x64

FROM docker.elastic.co/beats/filebeat:7.13.4
COPY --chown=root:filebeat filebeat.yml /usr/share/filebeat/filebeat.yml

FROM node:current-alpine

LABEL org.opencontainers.image.title="Test node App" \
      org.opencontainers.image.description="Create logs for Opensearch" \
      org.opencontainers.image.authors="@user"

# Create directory in container image for app code
RUN mkdir -p /usr/src/app

# Copy app code (.) to /usr/src/app in container image
COPY . /usr/src/app

# Set working directory context
WORKDIR /usr/src/app

RUN mkdir -p /usr/src/app/logs

RUN touch /usr/src/app/logs/log.log

RUN touch /usr/src/app/logs/error_log.log

RUN ln -sf /proc/1/fd/1 /usr/src/app/logs/log.log

RUN ln -sf /proc/1/fd/1 /usr/src/app/logs/error_log.log

# Install dependencies from packages.json
RUN npm install

# Command for container to execute
CMD [ "node", "index.js" ]

【问题讨论】:

  • 您在 docker build 遇到的错误是什么?
  • 不要那样做。花更多时间在文档上,您将了解应该运行单个 filebeat 容器。然后所有其他容器应该记录到 stdout/stderr 并从给定的标签开始,以便 filebeat 解析它们的输出。

标签: docker dockerfile containers filebeat


【解决方案1】:

我已经使用来自 github 的 ELK 容器进行了一些设置,删除了 logstash 并添加了 filebeat,你可以花时间看看它,希望它有帮助,它所做的只是从所有容器中获取所有日志并将它们发送到 kibana ,请确保将端口更改为本地计算机端口 (192....)

https://github.com/kisakyamukama/ELF.git

【讨论】:

    猜你喜欢
    • 2018-10-08
    • 2013-10-08
    • 2020-02-16
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2020-09-10
    相关资源
    最近更新 更多