DEV Community

Cover image for Docker Series: Run Grafana + Prometheus with Docker Compose in Ubuntu
Kevin Sheeran
Kevin Sheeran

Posted on

Docker Series: Run Grafana + Prometheus with Docker Compose in Ubuntu

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

  1. 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/

  2. Create a new directory for your Prometheus and Grafana configuration files:

mkdir ~/monitoring
cd ~/monitoring
Enter fullscreen mode Exit fullscreen mode
  1. Create a new Docker Compose file:
nano docker-compose.yml
Enter fullscreen mode Exit fullscreen mode
  1. 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:
Enter fullscreen mode Exit fullscreen mode
  1. Save and close the file
  2. Create a new Prometheus configuration file:
nano prometheus.yml
Enter fullscreen mode Exit fullscreen mode
  1. Paste the following configuration into the file:
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']
Enter fullscreen mode Exit fullscreen mode
  1. Save and close the faile.
  2. Start the Docker containers:
docker-compose up -d
Enter fullscreen mode Exit fullscreen mode
  1. Wait for a few seconds for the containers to start up, then navigate to http://localhost:3000/ in your web browser to access Grafana.

  2. 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.

  3. 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

Top comments (0)