← All insightsAutomation

Automating Grafana Loki from scratch

CodeWizard Academy · 30 April 2026 · 3 min read · Intermediate

Anything you do to Grafana Loki twice should be automated. This walks the path from a manual install to a repeatable, pipeline-driven setup.

1. Install it reproducibly

bash
docker run -d --name loki -p 3100:3100 grafana/loki:latest
docker run -d --name promtail -v $PWD/promtail.yaml:/etc/promtail/config.yml grafana/promtail

2. Describe the desired state

Promtail scraping local logs and shipping to Loki.

yaml
server: { http_listen_port: 9080 }
clients: [{ url: http://loki:3100/loki/api/v1/push }]
scrape_configs:
  - job_name: system
    static_configs:
      - targets: [localhost]
        labels: { job: varlogs, __path__: /var/log/*log }

3. Run it from CI

Query logs programmatically with logcli.

bash
logcli query '{app="web"} |= "error"' --since=1h --limit=100

Want senior help putting Grafana Loki to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult