Grafana can't see Loki when both run as docker images

Hello,

I am new to both Loki and Grafana and we are using both in a docker compose. The problem I have is that Grafana can’t seem to connect to Loki. My docker compose file is as follows:

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

  grafana:
    container_name: grafana
    image: grafana/grafana:11.6.0
    environment:
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_BASIC_ENABLED=false
    ports:
      - 3000:3000/tcp
    depends_on:
      - loki
    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://172.19.0.2:3100
           basicAuth: false
           isDefault: false
           version: 1
           editable: false
         EOF
         /run.sh

Both containers start fine and the IP Address for Loki is correct, but when I use the Grafana and I test the data source, it can’t connect.

Any ideas greatly appreciated.

Thanks

Michael

You’ll probably want to create a docker network and put both grafana and loki on it.

Hi Tonyswumac,

Thanks for the response. I have just figured it out and it was the local machine iptables not being configured correctly. Once I solved this it now is able to see each other.

Thanks

Michael