Install Prometheus Inside Docker Container in Linux

Install Prometheus Inside Docker Container in Linux

Prometheus is a time series database. It is used for event monitoring and alerting. Prometheus is an open-source project available under the Apache License 2.0.

This tutorial explains how to install Prometheus inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Install Prometheus

Create directory for storing Prometheus data:

sudo mkdir -p /opt/prometheus/data

Set user, which ID is 65534 as owner for newly created directory:

sudo chown -R 65534:65534 /opt/prometheus

Note: it doesn't matter that user (ID: 65534) doesn't exist on host system. This user will be created in the container.

  • Host network

Run the following command to create a container for Prometheus that uses host network:

docker run -d --name=prometheus --restart=always --network=host \
    -v /opt/prometheus/data:/prometheus \
    prom/prometheus
  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, Prometheus service is listening on port 9090. It can be changed with -p option.

docker network create app-net
docker run -d --name=prometheus --restart=always --network=app-net \
    -p 8080:9090 \
    -v /opt/prometheus/data:/prometheus \
    prom/prometheus

Testing Prometheus

Prometheus provides web UI. Open a web browser and go to http://<IP_ADDRESS>:9090, where <IP_ADDRESS> is the IP address of the system.

Prometheus Inside Docker Container in Linux

Uninstall Prometheus

To completely remove Prometheus, remove its container:

docker rm --force prometheus

Remove Prometheus image:

docker rmi prom/prometheus

You can also remove Prometheus data:

sudo rm -rf /opt/prometheus

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.