This repository contains a Dockerfile to create a Docker image for Prometheus using an Ubuntu base image.
URL:https://youtu.be/h4Sl21AKiDg?si=GjAxyuELKLsP1A_s
The provided Dockerfile performs the following steps:
- Base Image: Uses the official Ubuntu base image.
- Maintainer: Sets a maintainer label.
- Update and Install Packages: Updates the package list and installs necessary packages (wget, tar, gzip).
- Prometheus Version: Sets the Prometheus version to be installed.
- Create Directories: Creates directories for Prometheus configuration and data.
- Download and Install Prometheus: Downloads Prometheus, extracts it, and moves the binaries and configuration files to the appropriate locations.
- Expose Port: Exposes port 9090, which is used by Prometheus.
- Entrypoint: Sets the entrypoint to run Prometheus with the specified configuration file and storage path.
- Healthcheck: Adds a healthcheck to ensure Prometheus is running.
To build the Docker image, follow these steps:
-
Clone the repository:
sudo git clone https://github.com/Eliyaser/prometheus-docker-setup.git sudo chown -R $USER:$USER /opt/prometheus-docker-setup cd /opt
-
Build the Docker image:
sudo docker image build -t my-prometheus-image:v2.46.0 -f prometheus-docker-setup/2.46.0/ubuntu-linux.dockerfile prometheus-docker-setup/2.46.0/context
To run a container from the built image:
-
Run the container:
sudo docker run -d -p 9090:9090 --name my-prometheus-container my-prometheus-image:v2.46.0
-
Verify that Prometheus is running by opening your browser and navigating to:
http://192.168.101.5:9090
To stop, remove the container, and delete the Docker image, follow these steps:
-
Stop the container:
sudo docker stop my-prometheus-container
-
Remove the container:
sudo docker rm my-prometheus-container
-
Delete the image:
sudo docker rmi my-prometheus-image:v2.46.0
To verify that the container and image have been removed, you can list the existing containers and images:
-
List all containers (including stopped ones):
sudo docker ps -a
-
List all images:
sudo docker images
Here is the Dockerfile used in this repository:
# Use the official Ubuntu base image
FROM ubuntu:22.04
# Set the maintainer label
LABEL maintainer="[email protected]"
# Install system packages.
RUN set -x \
&& apt update \
&& apt upgrade -y \
&& apt install -y wget vim net-tools gcc make tar git unzip sysstat tree netcat nmap logrotate cron
# Install Supervisor.
RUN set -x \
&& apt install -y supervisor
# Set the Prometheus version
ENV PROMETHEUS_VERSION=2.46.0
# Create a directory for Prometheus
RUN mkdir -p /etc/prometheus /var/lib/prometheus
# Download and install Prometheus
RUN cd /tmp && \
wget https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz && \
tar -xvf prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz && \
cd prometheus-${PROMETHEUS_VERSION}.linux-amd64 && \
mv prometheus /usr/local/bin/ && \
mv promtool /usr/local/bin/ && \
mv prometheus.yml /etc/prometheus/ && \
mv consoles /etc/prometheus/ && \
mv console_libraries /etc/prometheus/ && \
rm -rf /tmp/prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz /tmp/prometheus-${PROMETHEUS_VERSION}.linux-amd64
# Expose Prometheus port
EXPOSE 9090
# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/prometheus", "--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/var/lib/prometheus"]
# Add a healthcheck
HEALTHCHECK CMD wget --spider http://localhost:9090/ || exit 1