Skip to main content
This guide shows how to run Prometheus inside a Docker container. The typical workflow is simple:
  • 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.
When running Prometheus in a container, the configuration format remains identical to running on a VM or bare-metal server. You still provide a prometheus.yml with your scrape_configs and global settings. Below is a minimal configuration that instructs Prometheus to scrape itself.
The image is a flowchart illustrating the setup of Prometheus Docker, showing steps like pulling the image from DockerHub, using a Prometheus configuration file, and setting ports and bind mounts.
Example prometheus.yml:
Notes about localhost inside a container
  • localhost:9090 refers 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=host on 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.
Create the 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:
Prometheus Docker run flags and their purpose 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.yml will 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
Accessing the Prometheus UI After the container starts, open your browser and go to: http://localhost:9090 This opens the Prometheus expression browser, status pages, and API endpoints. Links and references

Watch Video