Deploy Alertmanager Container with Docker Compose

Introduction

Prometheus Alertmanager is a component of the Prometheus monitoring and alerting toolkit. Its primary purpose is to handle alerts generated by Prometheus and manage their routing, grouping, and notification.

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 Prometheus alertmanager container using Docker Compose on Ubuntu 22.04 LTS Debian machine.

Step 1: Creating docker-compose.yml

To deploy Prometheus Alertmanager using Docker Compose, you’ll need to create a docker-compose.yml file with the necessary configuration. Below is a basic example to get you started::

To create a separate directory for Prometheus alertmanager’s docker-compose.yml file.

sudo mkdir alertmanager && cd alertmanager

To create a docker-compose.yml

sudo nano docker-compose.yml

Copy and paste the followings configuration.

version: '3'

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

volumes:
  alertmanager:

This Docker Compose file:

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

Save the docker-compose.yml file.

Create an alertmanager.yml configuration file in the same directory. This is a minimal example:

sudo nano alertmanager.yml

Paste the basic configuration.

global:
  resolve_timeout: 5m

route:
  receiver: 'webhook'
  group_by: ['alertname', 'instance']

receivers:
- name: 'webhook'
  webhook_configs:
  - url: 'http://alertmanager-webhook-receiver:5001'

In this example, alerts are grouped by alertname and instance, and notifications are sent to a webhook receiver.

Save the alertmanager.yml file.

Step 2: Deploy Alertmanager Container

In the directory where your docker-compose.yml file is located, run the following command to start the Alertmanager 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 Grafana.

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 Alertmanager

Step 5: Accessing Alertmanager GUI

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

Step 6: Destroying Alertmanager Container

We need to execute the given command to destroy the Alertmanager’s docker container under docker compose.

sudo docker compose down 

Conclusion

We have successfully deployed Alertmanager 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 Alertmanager Container with Docker Compose

Leave a Reply

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

Scroll to top