Setting Up Grafana with Docker Compose¶
Introduction to Grafana¶
Grafana is an open-source platform for monitoring and observability. It allows you to query, visualize, alert on, and understand your metrics no matter where they are stored.
Docker Compose Configuration for Grafana¶
This Docker Compose setup deploys Grafana in a Docker container, providing a powerful and flexible way to visualize and analyze your data.
Docker Compose File (docker-compose.yml)¶
version: "3.8"
services:
grafana:
image: grafana/grafana
container_name: grafana
restart: unless-stopped
ports:
- '3000:3000'
volumes:
- grafana-storage:/var/lib/grafana
volumes:
grafana-storage: {}
Key Components of the Configuration¶
Service: Grafana¶
- Image:
grafana/grafanais the Docker image used for Grafana. - Ports:
3000:3000maps port 3000 on the host to port 3000 in the container, where Grafana's web interface is accessible.- Volumes:
grafana-storage:/var/lib/grafanaprovides persistent storage for Grafana's data.- Restart Policy:
unless-stoppedensures that the Grafana service restarts automatically unless explicitly stopped.
Deploying Grafana¶
- Save the Docker Compose configuration in a
docker-compose.ymlfile. - Run
docker compose up -dto start Grafana in detached mode. - Access Grafana by navigating to
http://<host-ip>:3000.
Default credentials
Grafana's default login is admin / admin. You will be prompted to change the password on first login.
Configuring and Using Grafana¶
After logging in:
- Go to Connections → Data Sources → Add data source
- Select Prometheus and set the URL to
http://<prometheus-host-ip>:9090 - Click Save & Test to verify the connection
- Go to Dashboards → Import and enter a community dashboard ID (e.g.
1860for the Node Exporter Full dashboard)
Updating Grafana¶
Back up before updating
Your data lives in the grafana-storage named volume. Back this up before major version updates.
Youtube Video¶
If there is an issue with this guide or you wish to suggest changes, please raise an issue on GitHub.