Docker 容器不使用 loki 日志驱动程序登录到 loki

时间:2021-02-01 14:58:43

标签: amazon-ec2 docker-compose grafana-loki

我正在尝试在 AWS ec2 主机上的 docker 容器中使用 loki 日志驱动程序。下面的配置在我自己的 ubuntu 20.04 机器上运行良好,但在 ubuntu 16.04 ec2 主机上运行良好。 iptables 有一个环回规则和适当的 loki docker 端口:3100。我什至在安全组中打开了那个端口。 docker 版本为 20.10.2。

我尝试使用 localhost:3100、主机名:3100,以及 docker 容器名称。我有一个桥接网络,不想使用主机网络。我也不想使用容器 IP 地址。

在这个 SO 问题中没有任何内容对我有用。 How to access host port from docker container

这是我的 docker-compose.yaml,它可以在我的本地机器上运行,但不能在 ec2 中运行。

工具容器是一个 go html 服务器。工具和 loki 容器位于同一主机上。

我可以使用 curl 将日志从 alpine 容器发布到 loki 到 URL http://loki:3100/loki/api/v1/push,但不能从我的工具容器发布。我可以使用 telnet 连接,但 curl 超时。

version: '3.3'

networks:
  traefik:
    external: true
  loki: {}
  
services:

  tools:
    build: .
    container_name: tools
    restart: always
    networks:
      - traefik
      - loki
    extra_hosts:
      - "host.docker.internal:host-gateway"
    logging:
      driver: loki
      options: 
        loki-url: http://loki:3100/loki/api/v1/push
        loki-external-labels: job=tools
    labels:
    ...

这是我的 loki docker-compose.yaml

version: "3.8"

networks:
  traefik:
    external: true
  loki: {}

volumes:
  loki_data:
   
services:
  
  loki:
    container_name: "loki"
    image: grafana/loki:2.1.0
    restart: always
    networks:
      - traefik
      - loki
    ports:
      - 3100:3100
    volumes:
      - type: volume
        source: loki_data
        target: /data
      - type: bind
        source: ./config/s3-loki-bolt-conf.yml
        target: /etc/loki/local-config.yaml
    command: -config.file=/etc/loki/local-config.yaml        
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

docker 插件已安装

docker plugin ls
ID             NAME          DESCRIPTION           ENABLED
a03c22e8375e   loki:latest   Loki Logging Driver   true

sudo journalctl -u docker.service | grep loki 给我这个错误。

08 06:46:06 docker1 dockerd[30842]: time="2021-02-08T06:46:06-08:00" level=info msg="level=warn ts=2021-02-08T14:46:06.586642758Z caller=client.go:322 container_id=5a5fbd8a7077243de9db74f549ab619f783eda978ee234651ad1849263a534fe component=client host=localhost:3100 msg=\"error sending batch, will retry\" status=-1 error=\"Post \\\"http://localhost:3100/loki/api/v1/push\\\": context deadline exceeded\"" plugin=fef8734ec8cc2d252f8c4e73e3e91fe8293d2847c7ce1d6df2fb2172a1c288ce

0 个答案:

没有答案