"hello world" test for loki, promtail and grafana

Is there a basic docker-compose.yml that sets up loki, promtail and grafana ?

I just need two simple things:

  • There is a container that log “hello world” every minute.
  • I’m able to see the “hello world” log text in grafana.

I have spent a full day trying to get this working on my mac that is used for development and staging. I gave up as I think that the path to docker log files when running on mac is not the same as on linux. I also tried to get this working on ubuntu production server. Here I get “Data source connected, but no labels were received. Verify that Loki and Promtail are correctly configured.” when adding loki to grafana.

I do not understand why this is so complex. I just want to do:
docker compose up -d

And then see the logs in grafana.

I do not want to use the loki-docker-driver as then it is not possible to read the logs in portainer or docker-desktop ?

Hoping for a simple answer :slight_smile:

I would recommend to start with Linux, instead of trying both platforms the same time. Linux has host network mode, which is a easy to configure between containers.

services:
  grafana:
    container_name: grafana
    image: grafana/grafana:10.0.1
    network_mode: host
    restart: always
    volumes:
      - ./grafana:/var/lib/grafana

  loki:
    container_name: loki
    image: grafana/loki:2.8.0
    network_mode: host
    volumes:
      - ./loki/data:/loki
      - ./loki/loki.yml:/etc/loki/local-config.yaml

  promtail:
    image: grafana/promtail:2.8.0
    container_name: promtail
    network_mode: host
    volumes:
      - ./loki/promtail.yml:/etc/promtail/config.yml
      - /var/log/nginx:/var/log/nginx

I don’t have a hello world example, but our article is straightforward solution to configure Loki, Promtail, Grafana for NGINX + YouTube tutorial for dashboard configuration.

Hope it helps.

1 Like

Thanks @mikhailvolkov and @jangaraj

Thanks to you I got the same config working on my Mac and the Ubuntu docker hosts.
The key that unlocked the problem was in promtail volumes definition
/var/run/docker.sock:/var/run/docker.sock
And how scrape_configs was set up in promtail config file.

I also managed to get loki to log to a docker volume instead of the host disk / inside the loki container.

now I can do docker compose up - and it just works :slight_smile:

Is anyone need it - here is my two files
docker-compose.yml :

version: "3"

services:
  
  loki:
    container_name: loki
    image: grafana/loki:latest
    ports:
      - "3100:3100"
    volumes:
      - loki-data-volume:/loki
    command: -config.file=/etc/loki/local-config.yaml


  grafana:
    container_name: grafana
    image: grafana/grafana:latest
    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://loki:3100
        EOF
        /run.sh
    ports:
      - "3000:3000"
    depends_on:
      - loki

  promtail:
    container_name: promtail
    image: grafana/promtail:2.8.0
    volumes:
      - ./promtail-local-config.yaml:/etc/promtail/config.yaml:ro
      - /var/run/docker.sock:/var/run/docker.sock
    command: -config.file=/etc/promtail/config.yaml

networks:
  default:
    name: urbalurba-network

volumes:
  loki-data-volume:

promtail-local-config.yaml

server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

clients:
  - url: http://loki:3100/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'

3 Likes