the docker-compose.yml
This file is the “instruction manual” for Docker to know how to start the services
content:
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- "9090:9090"
volumes:
- prometheus.yml:/etc/prometheus/prometheus.yml
- /prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
extra_hosts:
- "host.docker.internal:host-gateway"
user: "root" # Ayuda con problemas de permisos en los volúmenes de Linux
restart: unless-stopped
the command to UP the services in containers is (in the same location):
docker-compose up -d
search by service:
docker ps -a --filter "name=prometheus"
Volumes
Docker containers are “ephemeral”: if you delete them, everything inside disappears. Volumes are bridges between your computer (host) and the container so that the data survives.
- a:b
- Left: The file you have in your folder
- where the service expects to find its configuration within the container
example:
prometheus.yml:/etc/prometheus/prometheus.yml
- Left: The file located in your ~/grafanaandprometheus folder
- Right: Where Prometheus expects to find its configuration within the container
- Left: A folder on your actual machine; Docker looks for it in the root of your system, not in your user folder
- Right: Prometheus’ internal database (TSDB)
- Function: This is where the metrics are stored. By mapping it, if the container breaks or you restart it, Prometheus rereads this folder and you recover the entire history
Image
Tells Docker to download the latest official version of Prometheus
Container_name
A human-like name so that when you run docker ps, it doesn’t assign a random name like nervous_feynman
command
These are extra commands you give Prometheus when it starts up
- –config.file: You tell it exactly where the .yml file is located
- –storage.tsdb.path: You confirm that it should save everything in /prometheus (which is the volume we mounted earlier)
extra_hosts
host.docker.internal:host-gateway
Because Prometheus runs within an isolated Docker network, it doesn’t know what “localhost” is.
This line tells Prometheus that host.docker.internal is the IP address of your actual server so it can retrieve metrics from your Spring Boot app
user: "root" and restart
User: On Linux, Prometheus sometimes doesn’t have permission to write to your user’s folders. By using root, you avoid “Permission Denied” errors when trying to create the database
Restart: If the server restarts or the process fails, Docker automatically restarts it