This guide uses Docker Compose to run Prometheus with persistent storage.
For Docker installation, see Docker.
mkdir -p /opt/prometheus/{data,config,rules}
cd /opt/prometheus
Create config/prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
Create docker-compose.yml:
services:
prometheus:
image: prom/prometheus:v3.10.0
container_name: prometheus
user: "65534:65534"
ports:
- "9090:9090"
volumes:
- ./config/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./data:/prometheus
- ./rules:/etc/prometheus/rules:ro
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=15d'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
- '--web.enable-lifecycle'
restart: unless-stopped
networks:
- monitoring
networks:
monitoring:
driver: bridge
docker compose up -d
Check container status:
docker compose ps
View logs:
docker compose logs -f prometheus
Access web UI at http://SERVER_IP:9090
docker compose exec prometheus wget -qO- http://localhost:9090/-/reload
curl http://localhost:9090/api/v1/targets
docker compose down
docker compose pull
docker compose up -d
./data volume preserves metrics across restarts--storage.tsdb.retention.time based on disk space./data directoryTo monitor the host system, add to docker-compose.yml:
node_exporter:
image: prom/node-exporter:v1.10.2
container_name: node_exporter
pid: host
restart: unless-stopped
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--path.rootfs=/rootfs'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
networks:
- monitoring
Then add to prometheus.yml:
- job_name: 'node'
static_configs:
- targets: ['node_exporter:9100']
Deploying Prometheus in containers for production? Our consulting covers:
Get expert help: office@linux-server-admin.com | Contact Page