Promtail does not collect logs from other containers

Hi , i am dealing with some problem trying deploy a loki stack locally using docker-compose

in summary, promtail logs this error

component=docker_discovery discovery=docker config=flog_scrape/unix:///var/run/docker.sock:80 msg="Unable to refresh target groups" err="error while listing containers: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I am working on windows 10, docker 20.10

share my docker compose file as well as my promtail config file


version: "3"

networks:
  loki:

services:
  loki:
    image: grafana/loki:2.8.0
    ports:
      - "3101:3100"
    command: -config.file=/etc/loki/local-config.yaml
    volumes:
      - ./loki-config.yml:/etc/loki/loki-config.yml
    networks:
      - loki

  promtail:
    image: grafana/promtail:2.8.0
    volumes:
      - promtail:/var/log
      - ./promtail-local-config.yaml:/etc/promtail/docker-config.yaml
    command: -config.file=/etc/promtail/docker-config.yaml
    networks:
      - loki

  grafana:
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    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 
          orgId: 1
          url: http://loki:3100
          basicAuth: false
          isDefault: true
          version: 1
          editable: false
        EOF
        /run.sh
    image: grafana/grafana:latest
    ports:
      - "3001:3000"
    networks:
      - loki

  flog:
    image: mingrammer/flog
    command: -f json -d 1s -l
    networks:
      - loki

volumes:
  promtail:
  sock:

server:
  http_listen_port: 9080
  grpc_listen_port: 0
  log_level: error

positions:
  filename: /tmp/positions.yaml

clients:
  - url: http://localhost:3101/loki/api/v1/push
  
scrape_configs:
  - job_name: flog_scrape
    docker_sd_configs:
      - host: unix:///var/run/docker.sock
        refresh_interval: 5s
    relabel_configs:
      - source_labels: ['__meta_docker_container_name']
        regex: '/(.*)'
        target_label: 'container'

any idea guys?
thanks!

1 Like

have the same problem,Will anyone answer?

1 Like

Hello. I had the same problem. Solved adding a volume to the docker socket on the promtail service definition (at the docker compose level) with this line: - /var/run/docker.sock:/var/run/docker.sock
In your case, it would be something like this:

  promtail:
    image: grafana/promtail:2.8.0
    volumes:
      - promtail:/var/log
      - ./promtail-local-config.yaml:/etc/promtail/docker-config.yaml
      - /var/run/docker.sock:/var/run/docker.sock

Hope this helps!

1 Like