Skip to content

Fix docker-compose for macOS Docker Desktop#54

Open
lewispb wants to merge 2 commits intomainfrom
fix-docker-compose-macos-compatibility
Open

Fix docker-compose for macOS Docker Desktop#54
lewispb wants to merge 2 commits intomainfrom
fix-docker-compose-macos-compatibility

Conversation

@lewispb
Copy link
Copy Markdown
Member

@lewispb lewispb commented Apr 9, 2026

Summary

  • Replace network_mode: host with explicit port mapping (ports: "9090:9090") so Prometheus is reachable on macOS/Windows Docker Desktop
  • Add extra_hosts: host.docker.internal:host-gateway so Prometheus can still scrape the Rails app running on the host
  • Update Prometheus scrape configs to target host.docker.internal instead of localhost
  • Apply the same fix to the test dummy's docker-compose and alertmanager service

Why

network_mode: host doesn'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 caused Prometheus::ApiClient::Client::RequestError (Connection refused) when navigating to uptime/status pages.

The host.docker.internal + host-gateway approach 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_test passes — all checks pass including generator output, server boot, metrics, and probe execution
  • Verified the generated docker-compose.yml contains the correct port mapping and extra_hosts
  • Test on macOS Docker Desktop to confirm Prometheus is reachable

Fixes #28

🤖 Generated with Claude Code

lewispb and others added 2 commits April 9, 2026 09:48
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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: host with explicit ports mapping and add extra_hosts: host.docker.internal:host-gateway for Prometheus.
  • Update Prometheus scrape configuration to target host.docker.internal instead of localhost.
  • Bump gem version to 0.3.0 and reflect it in Gemfile.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"
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- "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`.

Copilot uses AI. Check for mistakes.
container_name: <%= app_name %>-prometheus
network_mode: host
ports:
- "9090:9090"
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- "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).

Copilot uses AI. Check for mistakes.
@@ -9,4 +9,4 @@ scrape_configs:
- job_name: "upright"
scrape_interval: 5s
static_configs:
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
static_configs:
static_configs:
# Use `host.docker.internal` when Prometheus runs in Docker.
# If Prometheus runs directly on the host, use `localhost:9394` instead.

Copilot uses AI. Check for mistakes.
@@ -9,4 +9,4 @@ scrape_configs:
- job_name: "upright"
scrape_interval: 5s
static_configs:
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Comment thread lib/upright/version.rb
Comment on lines 1 to 3
module Upright
VERSION = "0.2.0"
VERSION = "0.3.0"
end
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker-compose.yml: network_mode: host doesn't work on macOS

2 participants