Conversation
Docker Desktop on macOS/Windows runs in a Linux VM, so network_mode: host refers to the VM's network rather than the host machine. This causes Prometheus to be unreachable from the Rails app. Replace with explicit port mapping and extra_hosts (host.docker.internal) which works cross-platform: natively on Docker Desktop, and via the host-gateway directive on Linux Docker Engine 20.10+. Fixes #28 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates Upright’s docker-compose setup to work on macOS/Windows Docker Desktop by removing network_mode: host, exposing Prometheus/Alertmanager via port mappings, and switching Prometheus scrape targets to host.docker.internal.
Changes:
- Replace
network_mode: hostwith explicitportsmapping and addextra_hosts: host.docker.internal:host-gatewayfor Prometheus. - Update Prometheus scrape configuration to target
host.docker.internalinstead oflocalhost. - Bump gem version to
0.3.0and reflect it inGemfile.lock.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dummy/docker-compose.yml | Switch dummy Prometheus/Alertmanager off host networking and expose ports. |
| test/dummy/config/prometheus.yml | Update dummy scrape target to host.docker.internal:9394. |
| lib/generators/upright/install/templates/docker-compose.yml | Apply the same docker-compose networking changes to the install generator template. |
| lib/generators/upright/install/templates/development_prometheus.yml | Update generated dev Prometheus scrape target to host.docker.internal:9394. |
| lib/upright/version.rb | Bump Upright version to 0.3.0. |
| Gemfile.lock | Update locked Upright version references to 0.3.0. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| container_name: upright-prometheus | ||
| network_mode: host | ||
| ports: | ||
| - "9090:9090" |
There was a problem hiding this comment.
extra_hosts: host.docker.internal:host-gateway relies on Docker Engine 20.10+ (and a Compose implementation that supports the special host-gateway value). Consider adding an inline comment or note in the dummy compose file about this minimum requirement and the fallback (upgrade Docker or switch back to network_mode: host on Linux) to avoid confusing startup errors on older Docker installs.
| - "9090:9090" | |
| - "9090:9090" | |
| # `host-gateway` requires Docker Engine 20.10+ and a Compose implementation | |
| # that supports the special value. On older Linux Docker setups, upgrade | |
| # Docker/Compose or switch back to `network_mode: host`. |
| container_name: <%= app_name %>-prometheus | ||
| network_mode: host | ||
| ports: | ||
| - "9090:9090" |
There was a problem hiding this comment.
The template uses extra_hosts: host.docker.internal:host-gateway, which requires Docker Engine 20.10+ (and a Compose implementation that supports host-gateway). Please document this requirement in the generated compose (or nearby docs) and provide a clear fallback for older Linux Docker setups to prevent hard-to-diagnose failures when bringing the stack up.
| - "9090:9090" | |
| - "9090:9090" | |
| # Requires Docker Engine 20.10+ and a Compose implementation that supports | |
| # the special `host-gateway` value in `extra_hosts`. | |
| # | |
| # If `docker compose up` fails on an older Linux Docker setup, replace | |
| # `host-gateway` below with your Docker host gateway IP (for example | |
| # `172.17.0.1`, adjusted for your environment). |
| @@ -9,4 +9,4 @@ scrape_configs: | |||
| - job_name: "upright" | |||
| scrape_interval: 5s | |||
| static_configs: | |||
There was a problem hiding this comment.
This scrape target is now Docker-specific (host.docker.internal). If someone runs Prometheus directly on the host (not in Docker), this hostname won’t resolve. Consider adding a brief comment in this config (or maintaining a separate non-Docker example) to clarify when host.docker.internal vs localhost should be used.
| static_configs: | |
| static_configs: | |
| # Use `host.docker.internal` when Prometheus runs in Docker. | |
| # If Prometheus runs directly on the host, use `localhost:9394` instead. |
| @@ -9,4 +9,4 @@ scrape_configs: | |||
| - job_name: "upright" | |||
| scrape_interval: 5s | |||
| static_configs: | |||
There was a problem hiding this comment.
The development Prometheus config now targets host.docker.internal, which is correct for Dockerized Prometheus scraping a host-run Rails app, but it diverges from the localhost:9394 example in the README. Consider adding an explanatory comment here (or updating the docs) to make it clear which target to use in each setup.
| static_configs: | |
| static_configs: | |
| # Use host.docker.internal when Prometheus runs in Docker and Rails runs on the host. | |
| # If Prometheus also runs directly on the host, use localhost:9394 instead. |
| module Upright | ||
| VERSION = "0.2.0" | ||
| VERSION = "0.3.0" | ||
| end |
There was a problem hiding this comment.
The PR description focuses on docker-compose/macOS fixes, but it also bumps the gem version to 0.3.0. Please either mention the version bump explicitly in the PR description (and ensure release notes/changelog capture this docker-compose change), or split the version bump into a separate release PR to keep scope clear.
Summary
network_mode: hostwith explicit port mapping (ports: "9090:9090") so Prometheus is reachable on macOS/Windows Docker Desktopextra_hosts: host.docker.internal:host-gatewayso Prometheus can still scrape the Rails app running on the hosthost.docker.internalinstead oflocalhostWhy
network_mode: hostdoesn't work on macOS Docker Desktop because Docker runs inside a Linux VM — "host" refers to the VM's network, not the Mac's localhost. This causedPrometheus::ApiClient::Client::RequestError (Connection refused)when navigating to uptime/status pages.The
host.docker.internal+host-gatewayapproach works cross-platform: natively on Docker Desktop (macOS/Windows), and via the host-gateway directive on Linux Docker Engine 20.10+.Test plan
bin/smoke_testpasses — all checks pass including generator output, server boot, metrics, and probe executiondocker-compose.ymlcontains the correct port mapping and extra_hostsFixes #28
🤖 Generated with Claude Code