I am trying to log my application into grafana/loki/promtail using the same docker compose ,and I get the following error when connecting to loki :
localhost:3100 -> 404 page not found
and when i try to hook it in grafana :
URL [http://loki:3100 ]-> Loki: Bad Gateway. 502. Bad Gateway
I have seen that you have to put in grafana the name of the container for it to detect it but I get the same error.
Both promtail and loki containers show no errors in their logs.
version: "3.7"
services:
my-service-to-log:
image: example:latest
ports:
- "8080:8080"
- "8443:8443"
loki:
image: grafana/loki:2.4.1
ports:
- "3100:3100"
volumes:
- "C:/path/loki-config.yaml:/etc/loki/local-config.yaml"
command: -config.file=/etc/loki/local-config.yaml
promtail:
image: grafana/promtail:2.4.1
volumes:
- "C:/path/promtail-config.yaml:/etc/promtail/config.yml"
- /var/log:/var/log
command: -config.file=/etc/promtail/config.yml
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
My loki-config.yaml
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
instance_addr: 127.0.0.1
kvstore:
store: inmemory
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
ruler:
alertmanager_url: http://localhost:9093
And my promtail-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: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /opt/app/logs/*.log
/ # nc -vz localhost 3100
localhost (127.0.0.1:3100) open
I have tried to nc from the grafana container to the loki container and it seems to see it …. any ideas ?
3
Answers
Loki needs to listen on all interfaces, not just localhost, when you want to access it from another container:
When adding Loki as a datasource in Grafana,
instead of http://localhost:3100,
use an ip address your computer has, instead of localhost.
Example http://LAN_IP_ADDR:3100
You must place all containers on the same virtual network. Without this, they cannot see each other.