Prometheus and Docker Compose

How to setup prometheus for local development

1. Create a docker-compose.yml file

INFO

If your application is running on your development machine natively, you must use the network_mode: host to access the docker container on the host machine.

docker-compose.yml
version: '3.7' services: prometheus: image: prom/prometheus:latest restart: unless-stopped network_mode: host # use host network to access the host machine ports: - '9090:9090' volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml

2. Create a prometheus.yml file

prometheus.yml
global: scrape_interval: 5s # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: 'app' # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: - job_name: 'backend' static_configs: - targets: ['localhost:3001'] # Metrics endpoint of the frontend application labels: group: 'app'
INFO

If you want to see a real world example, check out the demo repo.

Screenshots

Shows a prometheus query
Shows the prometheus targets