Skip to content

fix: replace host networking with exposed ports for macOS compatibility#69

Merged
tmm merged 1 commit intowevm:mainfrom
brendanjryan:fix/testcontainers-macos-host-networking
Mar 24, 2026
Merged

fix: replace host networking with exposed ports for macOS compatibility#69
tmm merged 1 commit intowevm:mainfrom
brendanjryan:fix/testcontainers-macos-host-networking

Conversation

@brendanjryan
Copy link
Contributor

@brendanjryan brendanjryan commented Mar 24, 2026

Problem

Fixes #66. Instance.tempo() from prool/testcontainers doesn't work on macOS because it uses withNetworkMode('host'), which only works on Linux. On macOS, Docker Desktop runs containers in a Linux VM, so host networking doesn't expose ports to the Mac host.

Solution

Replace withNetworkMode('host') with withExposedPorts(containerPort) and use Testcontainers' standard port mapping APIs (getHost() / getMappedPort()) to discover the actual endpoint after the container starts.

Since the Instance.define() wrapper previously froze host/port as constants at create() time, the inner start() return type is widened to optionally return { host?, port? }. When returned, these values update the instance's exposed host/port getters before the public start() promise resolves — so Pool and Server consumers see the correct mapped endpoint with no changes needed.

Aside: Why not fixed host-port binding?

Using { container: port, host: port } would avoid the interface change but introduces a TOCTOU race between getPort() and Docker's bind — especially problematic on Docker Desktop where startup latency widens the window. Random mapped ports are the Testcontainers-recommended approach and work better with parallel test runs.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 24, 2026

Open in StackBlitz

npm i https://pkg.pr.new/prool@69

commit: 4e6baf0

@brendanjryan brendanjryan force-pushed the fix/testcontainers-macos-host-networking branch 5 times, most recently from b5fbe48 to 16d60fe Compare March 24, 2026 16:14
Fixes wevm#66. The testcontainers Tempo instance used withNetworkMode('host')
which only works on Linux. On macOS, Docker Desktop runs in a VM so host
networking doesn't expose ports to the Mac host.

Changes:
- testcontainers/Instance.ts: Replace withNetworkMode('host') with
  withExposedPorts(containerPort), return dynamic {host, port} from
  started.getHost()/getMappedPort() after container start
- Instance.ts: Widen internal start() return type to allow
  {host?, port?}, convert host/port to let+getters so they update
  dynamically after start resolves
- Instance.test.ts: Add regression tests for dynamic host/port
  propagation and void-return backward compatibility
@brendanjryan brendanjryan force-pushed the fix/testcontainers-macos-host-networking branch from 16d60fe to 4e6baf0 Compare March 24, 2026 16:15
@brendanjryan
Copy link
Contributor Author

tests will fail until #70 lands due to tempo timeout

@tmm tmm merged commit c6c3e63 into wevm:main Mar 24, 2026
5 of 6 checks passed
@brendanjryan brendanjryan deleted the fix/testcontainers-macos-host-networking branch March 24, 2026 17:00
brendanjryan added a commit to brendanjryan/prool that referenced this pull request Mar 24, 2026
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.

Tempo instance doesn't work on macOS due to network_mode: host

2 participants