Sometimes there is need to dig trough logs stored in Grafana Loki on CLI. Building temporary docker container for just logcli is an option.

  1. Start debian docker. docker run --name debian --network loki -ti debian:latest
    You should end up in root shell prompt inside debian docker container. If you need data exported to host’s disk than bind mount some folder inside container.

  2. Install prerequisites.
     apt update
     apt install wget unzip
    
  3. Pull precompiled logcli from github. replace ‘'’v2.8.2’’’ with whatever current and do not forget select correct CPU architecture.
     cd root
     wget https://github.com/grafana/loki/releases/download/v2.8.2/logcli-linux-amd64.zip
    
  4. unzip and rename
     unzip logcli-linux-amd64.zip
     Archive:  logcli-linux-amd64.zip
       inflating: logcli-linux-amd64   
     mv logcli-linux-amd64 logcli
    
  5. Point logcli to where is your Loki server is located
     export LOKI_ADDR="http://loki.example.com:3100"
    
  6. Run your queries
     ./logcli query --timezone=Local --from="2023-05-02T00:00:00Z"  --to="2023-05-02T01:00:00Z" --limit=0  '{job="syslog"}'
    

Updated: