fix(compose): forward port mappings to container run (-p)#20
Closed
itxtoledo wants to merge 1 commit into
Closed
Conversation
`buildRunArguments()` was not translating `ContainerConfig.ports` into `-p` flags for the native `container run` command. Instead it relied on `PortProxy` which spawns a background TCP relay (`mocker __proxy`) — this fails because the mocker CLI lacks the `com.apple.security.network.server` entitlement to bind host ports. The native `container` CLI already handles port forwarding correctly when invoked with `-p`, so this change passes the port mappings directly. Fixes us#19 💘 Generated with Crush Assisted-by: Crush:deepseek-v4-pro
Owner
|
Thank you so much for this, @itxtoledo! 🙏💚 You nailed the exact same root cause and fix — This is shipping in v0.3.3. Please don't let a closed PR discourage you — your report + PR moved this forward fast, and contributions like this are exactly what makes the project better. Hope to see you around here again! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #19.
Problem
mocker compose upshowed port mappings inmocker compose psoutput but no ports were actually reachable on the host — every published port returnedECONNREFUSED. Meanwhile, the nativecontainer run -p <port>worked correctly.Root cause
ContainerEngine.buildRunArguments()never included-pflags when building thecontainer runargument list. Instead, it relied onPortProxy— a background subprocess (mocker __proxy) that creates aNWListenerto relay TCP traffic to the container IP. This proxy fails because:com.apple.security.network.serverentitlement needed to bind host portsNWListenerrequires App Sandbox or the network server entitlement, neither of which the CLI hasThe native
containerCLI already handles port forwarding correctly when invoked with-p, so the simplest fix is to pass the port mappings directly.Changes
Sources/MockerKit/Container/ContainerEngine.swift— Added-pflags tobuildRunArguments()(4 lines):Tests/MockerKitTests/ContainerEngineTests.swift— New unit testtestRunArgumentsIncludePortMappings(16 lines) verifies:-pflag is present in the argument listhost:container/protocolformatTests
swift build— compiles without errorsswift test— 82 tests in 9 suites pass (including new test)mocker compose down && mocker compose up -dwith a 5-service compose file — all 5 ports respondOPEN(previously allECONNREFUSED)18080:80confirmed reachable