version: '3.8'

services:
  loki:
    image: grafana/loki:2.8.0
    container_name: loki
    ports:
      - "3100:3100"
    command: -config.file=/etc/loki/local-config.yaml
    user: "10001:10001"  # Ensure the container runs with the correct user
    volumes:
      - ./loki-config.yaml:/etc/loki/local-config.yaml
      - /var/loki:/var/loki  # Ensure this directory exists and is writable
    networks:
      - loki-network

  promtail:
    image: grafana/promtail:2.8.0
    container_name: promtail
    volumes:
      - ./promtail-config.yaml:/etc/promtail/config.yml
      - /var/log:/var/log
    command: -config.file=/etc/promtail/config.yml
    networks:
      - loki-network

  grafana:
    image: grafana/grafana:10.0.0  # Replace with the latest stable version
    container_name: grafana
    ports:
      - "3030:3000"
    networks:
      - loki-network
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin  # Change this password for security
    depends_on:
      - loki
      - promtail

networks:
  loki-network:
    driver: bridge
