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
1version:'3.7'2services:3prometheus:4image: prom/prometheus:latest
5restart: unless-stopped
6network_mode: host # use host network to access the host machine7ports:8-'9090:9090'9volumes:10- ./prometheus.yml:/etc/prometheus/prometheus.yml
1global:2scrape_interval: 5s
34# Attach these labels to any time series or alerts when communicating with5# external systems (federation, remote storage, Alertmanager).6external_labels:7monitor:'app'89# A scrape configuration containing exactly one endpoint to scrape:10# Here it's Prometheus itself.11scrape_configs:12-job_name:'backend'13static_configs:14-targets:['localhost:3001']# Metrics endpoint of the frontend application15labels:16group:'app'
INFO
If you want to see a real world example, check out the demo repo.