# Day 75 - Sending Docker Log to Grafana

Step 1: Install Docker Begin by installing Docker on your system. Run the following commands:

```bash
  sudo apt-get update
  sudo apt-get install docker.io -y

  # Giving docker permission to current user
  sudo usermod -aG docker $USER
  sudo reboot

  # Verify Docker version
  docker --version
```

After the system reboots, verify the Docker installation by running `docker --version`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689691945666/90ec3da9-aad8-4282-918d-b9ef89d6e2a7.png align="center")

Step 2: Configure Loki Download the Loki configuration file using the following command:

```bash
  wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689691936506/a1e4c907-ccb0-43bb-8775-6172444a23e0.png align="center")

Next, start the Loki container with the downloaded configuration file:

```bash
docker run -d --name loki -v $(pwd)/loki-config.yaml:/mnt/config/loki-config.yaml -p 3100:3100 grafana/loki:2.8.0 --config.file=/mnt/config/loki-config.yaml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689693697971/fecbaeef-e163-478a-8917-eee13bdb8d4f.png align="center")

Now check the container

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689738852830/eac52dcc-4e50-4ed0-9c3c-09d2674d986d.png align="center")

Make sure to open port 3100 in your security group to allow access to Loki. You can now check the Loki metrics using `http://<public_ip>:3100/metrics`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689693831024/7ca4f8ae-9e13-4309-b4b2-af15c90673bc.png align="center")

verify its readiness with `http://<public_ip>:3100/ready`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689693932180/5a40154c-0728-448b-8035-c1b3dc2103e7.png align="center")

Step 3: Download and Configure Promtail Download the Promtail configuration file using the following command:

```bash
  wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689694008341/02144099-85d7-4c28-bfa0-099b01f8e30d.png align="center")

check your promtail:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689694087605/d698f602-ae8f-41bf-b496-cc6c4cf8aaed.png align="center")

Run the Promtail container with the downloaded configuration file:

```bash
docker run -d --name promtail -v $(pwd)/promtail-config.yaml:/mnt/config/promtail-config.yaml -v /var/log:/var/log --link loki grafana/promtail:2.8.0 --config.file=/mnt/config/promtail-config.yaml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689739132620/e774fabd-29ed-4446-918e-52b0499d3b39.png align="center")

Verify that both Loki and Promtail containers are running by executing `docker ps` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689739209677/383bfab8-a3ec-40e0-b2d3-0b0535d99adf.png align="center")

Step 4: Configure Loki as a Data Source in Grafana

Login to your Grafana instance and follow these steps:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689739378403/7d6dc0ba-bf87-4047-9850-eca408e8f2b2.png align="center")

Go to "Configuration" &gt; "Data Sources" from the left menu panel.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689739474837/0f3d8fe1-4eec-4807-9ef6-9795d1bcdab7.png align="center")

Click on "Add New Data Source" from the top right corner.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689739544246/4d6116d5-35a3-4ff9-81f7-080e589864be.png align="center")

Search for "Loki" and click on it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689739602167/e4b55980-7d29-4f0f-ac3f-a873c6d94d7b.png align="center")

Fill in the details, such as the name of the data source and the HTTP URL (e.g., [`http://Your-IP:3100`](http://Your-IP:3100)).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689739683777/f6a033b2-a03c-4f34-9a8d-0ecdb4f1c1e4.png align="center")

Click on "Save and Test" to verify the connection.

Step 5: Visualize Docker Logs in Grafana

To explore and visualize the Docker logs, follow these steps:

Click on "Explore" from the top right corner of the Grafana interface.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689739791019/80c43a94-4a42-4f6f-8bb3-4e5e00c4c234.png align="center")

Select the desired time range and adjust other settings as needed.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689740023913/931b64bd-6b81-42cb-b6fe-8e9f1f39bd34.png align="center")

Run queries to fetch the Docker logs and observe the results.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689740090428/6df2a087-d7fb-4446-84b3-21dc14ec9589.png align="center")

To create a dashboard, click on "Add to Dashboard" from the top right corner.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689740160175/4acecd9e-255e-49d8-abc5-672b615f0e67.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689740211547/17981753-bfae-426a-ab34-81ea49620701.png align="center")

That was all for today. See you another day with another challenge.
