You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

启动OpenTelemetry Collector失败:配置路径为目录致读取错误求助

解决OpenTelemetry Collector启动时的配置文件目录错误问题

错误原因

容器内指定的配置路径/etc/otel-collector-config.yaml被识别为目录而非文件。这是因为Docker卷挂载配置错误——要么把本地目录映射到了容器的文件路径上,要么本地路径本身就是目录而非配置文件。

解决步骤

  1. 确保本地存在正确的配置文件
    先检查当前工作目录下是否有otel-collector-config.yaml文件。如果没有,创建该文件并写入官方示例配置:

    receivers:
      otlp:
        protocols:
          grpc:
            endpoint: 0.0.0.0:4317
          http:
            endpoint: 0.0.0.0:4318
    
      prometheus:
        config:
          scrape_configs:
            - job_name: 'otel-collector'
              scrape_interval: 10s
              static_configs:
                - targets: ['0.0.0.0:8888']
    
    processors:
      batch:
    
    exporters:
      logging:
        loglevel: debug
    
    service:
      pipelines:
        traces:
          receivers: [otlp]
          processors: [batch]
          exporters: [logging]
        metrics:
          receivers: [otlp, prometheus]
          processors: [batch]
          exporters: [logging]
    
  2. 修正Docker Compose的卷挂载配置
    打开docker-compose.yml,检查volumes字段的挂载规则,确保是本地文件映射到容器内的文件路径,不要在容器路径末尾加斜杠。正确配置示例:

    version: '3.8'
    services:
      otel-collector:
        image: otel/opentelemetry-collector-contrib:latest
        volumes:
          - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
        command: ["--config=/etc/otel-collector-config.yaml"]
        ports:
          - "4317:4317"
          - "4318:4318"
          - "8888:8888"
    

    若本地曾误将otel-collector-config.yaml创建为目录,先删除该目录:

    rm -rf ./otel-collector-config.yaml
    
  3. 重新启动服务
    停止并重新启动容器,确保挂载配置生效:

    docker-compose down
    docker-compose up -d
    

额外排查点

  • 检查本地配置文件的权限,确保Docker容器有读取权限:
    chmod 644 ./otel-collector-config.yaml
    
  • 若相对路径解析有问题,可替换为本地配置文件的绝对路径,例如:
    volumes:
      - /home/user/otel/otel-collector-config.yaml:/etc/otel-collector-config.yaml
    

内容的提问来源于stack exchange,提问作者Joseph Antony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 03:33:16