Docker Series: Run Grafana + Prometheus with Docker Compose in Ubuntu
Kevin Sheeran
Posted on April 27, 2023
Hi, there! Since docker has become more and more popular in CI/CD world, today I will be using a brief hands-on experience on how to run Grafana and Prometheus with Docker Compose in Ubuntu system
Install Docker on your Ubuntu machine. You can do this by following the official Docker installation guide for Ubuntu: https://docs.docker.com/engine/install/ubuntu/
Create a new directory for your Prometheus and Grafana configuration files:
mkdir ~/monitoring
cd ~/monitoring
- Create a new Docker Compose file:
nano docker-compose.yml
- Paste the following configuration into the file:
version: '3'
services:
prometheus:
image: prom/prometheus
container_name: prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- --config.file=/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
networks:
- monitoring
grafana:
image: grafana/grafana
container_name: grafana
volumes:
- grafana_data:/var/lib/grafana
ports:
- "3000:3000"
networks:
- monitoring
volumes:
grafana_data:
networks:
monitoring:
- Save and close the file
- Create a new Prometheus configuration file:
nano prometheus.yml
- Paste the following configuration into the file:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- Save and close the faile.
- Start the Docker containers:
docker-compose up -d
Wait for a few seconds for the containers to start up, then navigate to http://localhost:3000/ in your web browser to access Grafana.
Log in to Grafana using the default credentials (username: admin, password: admin), then add a new data source by clicking on the "Add data source" button and selecting "Prometheus" as the data source type.
Configure the Prometheus data source by specifying the URL as http://prometheus:9090/ and clicking on the "Save & Test" button.
You can now create dashboards in Grafana and start monitoring your applications with Prometheus.
That's it! You now have a working setup of Grafana and Prometheus running with Docker on Ubuntu
Posted on April 27, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024