Loki logging docker driver not working with docker compose?

I have been trying to get log information from grafana.log into loki use the logging driver but it does not seem to like something in my docker compose file.

Does anyone know how i can get the content of grafana.log sent to loki so I can see them in the explore tab in grafana?

version: "3"

networks:
  loki:
  influxdb:

services:
  influxdb:
    image: influxdb:1.7
    restart: always
    ports:
      - '8086:8086'
    volumes:
      - influxdb-storage:/var/lib/influxdb
    environment:
      INFLUXDB_DB: actualdb
    networks:
      - influxdb

  read:
    image: grafana/loki:2.4.2
    command: "-config.file=/etc/loki/config.yaml -target=read"
    ports:
      - 3100
      - 7946
      - 9095
    volumes:
      - ./loki-config.yaml:/etc/loki/config.yaml
    networks: &loki-dns
      loki:
        aliases:
          - loki

  write:
    image: grafana/loki:2.4.2
    command: "-config.file=/etc/loki/config.yaml -target=write"
    ports:
      - 3100
      - 7946
      - 9095
    volumes:
      - ./loki-config.yaml:/etc/loki/config.yaml
    networks:
      <<: *loki-dns

  grafana:
    image: grafana/grafana:latest
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    depends_on:
      - gateway
      - influxdb
    volumes:
      - grafana-storage:/var/lib/grafana
    entrypoint:
      - sh
      - -euc
      - |
        mkdir -p /etc/grafana/provisioning/datasources
        cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
        apiVersion: 1
        datasources:
          - name: Loki
            type: loki
            access: proxy
            url: http://gateway:3100
            jsonData:
              httpHeaderName1: "X-Scope-OrgID"
            secureJsonData:
              httpHeaderValue1: "tenant1"
          - name: InfluxDB_v1
            type: influxdb
            access: proxy
            url: http://influxdb:8086
            database: actualdb
            user: admin
            password: admin
            editable: true
        EOF
        /run.sh
    ports:
      - "8080:3000"
    networks:
      - loki
      - influxdb
    logging:
      driver: loki
      options:
        loki-url: "http://host.docker.internal:3100/loki/api/v1/push"
        loki-pipeline-stages: |
          - regex:
              expression: '(level|lvl|severity)=(?P<level>\w+)'
          - labels:
              level:
    extra_hosts:
      - "host.docker.internal:host-gateway"

  gateway:
    image: nginx:latest
    depends_on:
      - read
      - write
    entrypoint:
      - sh
      - -euc
      - |
        cat <<EOF > /etc/nginx/nginx.conf
        user  nginx;
        worker_processes  16;  ## Default: 1
        events {
          worker_connections   1000;
        }
        http {
          resolver 127.0.0.11;
          server {
            listen             3100;
            location = / {
              return 200 'OK';
              auth_basic off;
            }
            location = /api/prom/push {
              proxy_pass       http://write:3100\$$request_uri;
            }
            location = /api/prom/tail {
              proxy_pass       http://read:3100\$$request_uri;
              proxy_set_header Upgrade \$$http_upgrade;
              proxy_set_header Connection "upgrade";
            }
            location ~ /api/prom/.* {
              proxy_pass       http://read:3100\$$request_uri;
            }
            location = /loki/api/v1/push {
              proxy_pass       http://write:3100\$$request_uri;
            }
            location = /loki/api/v1/tail {
              proxy_pass       http://read:3100\$$request_uri;
              proxy_set_header Upgrade \$$http_upgrade;
              proxy_set_header Connection "upgrade";
            }
            location ~ /loki/api/.* {
              proxy_pass       http://read:3100\$$request_uri;
            }
          }
        }
        EOF
        /docker-entrypoint.sh nginx -g "daemon off;"
    ports:
      - "3100:3100"
    networks:
      - loki

volumes:
  grafana-storage:
    external: true
  influxdb-storage:
    external: true

References:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.