Dockerized Grafana not able to use Dockerized Loki+Promtail as data source

Hi all, first-time poster, and a fan of the whole Grafana-Loki-Promtail setup.

I am currently setting up a system where Grafana, Loki and Promtail are running in separate containers in Docker (and managed via Compose), but all within the same Docker network. I’ve managed to get all three up, but when I tried to configure Grafana to use Loki as a data source, I got the “Unable to connect with Loki. Please check the server logs for more details.” error.

Loki seems to be running fine; when I go to http://localhost:3100/ready, I got the “ready” message. Output on the screen (I ran the docker compose command without the -d switch) also not showing any abnormalities. And if it is a factor, I’m running these in W10.

For reference, here are the relevant Compose profiles:

grafana:
    image: "grafana/grafana-enterprise"
    profiles:
      - grafana
    environment:
      - GF_SERVER_HTTP_PORT=3500      
    ports:
      - "3500:3500"
    volumes:
      - "<local path>:/var/lib/grafana"
    networks:
      - "grafana_network"


  loki:
    image: grafana/loki
    profiles:
      - loki
    ports:
      - "3100:3100"
    volumes:
      - "<local-path>:/etc/loki"
    command: -config.file=/etc/loki/loki-local-config.yaml
    networks:
      - "grafana_network"
    

  promtail:
    image: grafana/promtail
    profiles:
      - promtail
    volumes:
      - "<local path>:/etc/promtail"
      - "<local path>:/var/log"
    command: -config.file=/etc/promtail/promtail-local-config.yaml
    networks:
      - "grafana_network"

Try using http://loki:3100 as data source instead of localhost.

IT WORKED! Thank you very much for the assistance.

But I’m curious, how does “loki” points to the container? Is it because I named the profile “loki”? I don’t think I’ve seen this in the documentation.

It’s a Docker-Compose question, not a Grafana one, so it’s expected from you to understand docker as your underlying platform (and then not explicit shown in Grafana’s docs): when you use docker-compose the orquestration itself do a setup for every hosts file inside every container, using the service name of each container.

“localhost” would never work, since each “localhost” for each container in each service would never point to the local machine, but for the container itself. Then, the localhost of grafana service would never get a 3100 port.

Hope it helps.

It does. Thank you very much for your assistance.

1 Like