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:latestrestart:unless-stoppednetwork_mode:host# use host network to access the host machineports: - '9090:9090'volumes: - ./prometheus.yml:/etc/prometheus/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 applicationlabels:group:'app'
INFO
If you want to see a real world example, check out the demo repo.