Deploy Prometheus Container with Docker Compose

Introduction

Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability of systems and applications. It was originally developed by SoundCloud and later donated to the Cloud Native Computing Foundation (CNCF). Prometheus is widely used in the field of DevOps and system administration for monitoring and observability purposes.

Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define an entire application stack, including services, networks, and volumes, in a single file called docker-compose.yml. With a single command, you can then spin up your entire application stack, simplifying the process of managing and deploying multi-container Docker applications.

Prerequisites

  • Up and running ubuntu 22.04 LTS machine.
  • Basic knowledge in linux commands.
  • Internet connectivity.
  • Docker and docker compose should installed on your machine.

To install Docker and docker compose on ubuntu 22.04 LTS, We can use the given link.

In this post, We will deploy Prometheus time series database server using Docker Compose on Ubuntu 22.04 LTS Debian machine.

Step 1: Creating docker-compose.yml

To deploy Prometheus using Docker Compose, you can create a docker-compose.yml file with the necessary configuration. Here’s a basic example to help you get started:

To create a docker-compose.yml

sudo nano docker-compose.yml

Copy and paste the followings configuration.

version: '3'

services:
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus:/etc/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'

volumes:
  prometheus:

This Docker Compose file:

  • Uses the official Prometheus image.
  • Maps port 9090 to the host machine.
  • Mounts a local directory ./prometheus to the container’s /etc/prometheus directory.
  • Specifies a custom configuration file (prometheus.yml) using the --config.file option.

Save the docker-compose.yml file.

Create a prometheus.yml configuration file in the same directory:

sudo nano prometheus.yml

Paste the following basic configuration.

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

This minimal configuration sets up Prometheus to scrape its own metrics..

Save the prometheus.yml file.

Step 2: Deploy Prometheus Container

In the directory where your docker-compose.yml file is located, run the following command to start the Prometheus container:

sudo docker-compose up -d

The -d flag runs the containers in the background, It will take few sec or mins to pull the image and deploy the Prometheus.

Step 3: Validate the Container

To check the running containers launched by Docker Compose, you can use the following command:

sudo docker-compose ps

This command provides a summary of the status of each service defined in your docker-compose.yml file. It shows information such as the service name, container ID, status, ports, and names.

Step 4: Logging

Some time we need to also check the real time logs, So we can use the given commands.

sudo docker-compose logs -f prometheus

Step 5: Accessing Prometheus

Access Prometheus by opening your web browser and navigating to http://localhost:9090or http://IPaddress:9090.

Prometheus up and running in a Docker container using Docker Compose. You can customize the prometheus.yml file to add additional scrape configurations for other services and adjust Prometheus settings according to your requirements.

Conclusion

We have successfully deployed Prometheus time series database server on docker’s container using docker compose on ubuntu 22.04 LTS Debian machine, If you still have questions, please post them in the comments section below.

Author

Deploy Prometheus Container with Docker Compose

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top