- Pull the official Prometheus image from Docker Hub.
- Provide a Prometheus configuration file (
prometheus.yml) from the host into the container using a bind mount. - Expose Prometheus’ HTTP port so you can access the UI and API.
prometheus.yml with your scrape_configs and global settings. Below is a minimal configuration that instructs Prometheus to scrape itself.

prometheus.yml:
localhost inside a container
localhost:9090refers to the container’s loopback interface. Use this target when Prometheus scrapes metrics exposed by processes running in the same container (for example, Prometheus scraping itself).- To scrape services running on the Docker host from inside the container, use
host.docker.internal:PORT(supported on Docker Desktop) or run the container with--network=hoston Linux. See Docker networking docs for more details: https://docs.docker.com/desktop/networking/
If you need Prometheus inside the container to reach services on the Docker host, prefer
host.docker.internal on Docker Desktop. On Linux, --network=host is an easy option, but it only works on Linux hosts.prometheus.yml on your host (for example with vi or your preferred editor), then run the Prometheus container with a bind mount that maps your host configuration into /etc/prometheus/prometheus.yml inside the container. Expose port 9090 so you can access Prometheus from the host browser.
Example commands:
Best practices and operational notes
- Always use an absolute path for the host side of bind mounts (e.g.,
/home/user/prometheus.yml), otherwise Docker may create unexpected anonymous volumes. - The bind mount keeps the container’s Prometheus configuration in sync with the host file: editing the host
prometheus.ymlwill immediately update the file inside the container. Prometheus, however, needs to reload the configuration for changes to take effect.
Prometheus will not automatically apply edited configs unless it reloads them. Either restart the container or trigger a config reload via Prometheus’ reload mechanism (for example, POST to
/-/reload if available). Check the Prometheus configuration reloading docs: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#reloading-configuration- Prometheus configuration and reloading: https://prometheus.io/docs/prometheus/latest/configuration/configuration/
- Docker networking (host.docker.internal, networking details): https://docs.docker.com/desktop/networking/
- Official Prometheus Docker image on Docker Hub: https://hub.docker.com/r/prom/prometheus