Repository navigation
fix(dockerutil): fall back to NetworkSettings.Ports in GetBoundHostPorts (#8657) [skip ci] - #8657
Merged
Merged
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
GetBoundHostPorts() only read HostConfig.PortBindings, which is the binding that was *requested* at container-create time. Some providers (socktainer/Apple Container, observed while investigating ddev#7372) return an empty HostConfig.PortBindings on inspect even though the container has ports bound, while NetworkSettings.Ports - the binding actually in effect - is populated correctly. The empty result fed GetAvailableRouterPort(), which uses it to decide whether ddev-router already owns a proposed port before probing host availability. With no bound ports visible, every router port looked unclaimed, the host-availability probe found the router's own listener and called it busy, and DDEV allocated a fresh ephemeral port on every command that touches the router (e.g. `ddev ssh`), silently rewriting the project's URLs each time. Extracted the port-collecting loop into addBoundHostPorts() so it can build the result from either source, and fall back to NetworkSettings.Ports only when HostConfig.PortBindings yields nothing - real Docker keeps HostConfig.PortBindings populated, so behavior there is unchanged. Verified live against a running ddev-router on socktainer: the same inspect that reports HostConfig.PortBindings as null carries the correct ports in NetworkSettings.Ports. Added TestAddBoundHostPorts covering the merge/fallback/empty-HostPort cases; existing TestGetBoundHostPorts continues to pass unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
rfay
force-pushed
the
20260802_rfay_bound_host_ports_fallback
branch
from
August 11, 2026 19:45
b0f196d to
0321934
Compare
rfay
marked this pull request as ready for review
August 11, 2026 19:46
Member
Author
|
I guess this is safe but annoying. Probably reasonable. |
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.
The Issue
GetBoundHostPorts()only readsHostConfig.PortBindings(the requestedport bindings) to figure out which host ports a container has bound. On
socktainer (the Docker-compatible API in front of Apple Container), that
field comes back empty even for containers with real, working port
bindings — only
NetworkSettings.Ports(the actual bindings) ispopulated. The practical effect: DDEV thinks the port is free and tries to
reallocate it, when it's actually already in use by the running container.
This is a real (if narrow) DDEV bug independent of Apple Container: the
Docker API documents
HostConfig.PortBindingsandNetworkSettings.Portsas separate, sometimes-divergent fields, and DDEV was only ever reading
one of them.
How This PR Solves The Issue
GetBoundHostPorts()now falls back toNetworkSettings.PortswhenHostConfig.PortBindingsyields no bound ports, via a sharedaddBoundHostPorts()helper used for both fields.Manual Testing Instructions
go test -v ./pkg/dockerutil -run TestAddBoundHostPortsdockerdpopulatesboth fields), so existing behavior is unchanged; verified live against
socktainer where the fallback path is what actually fires.
Automated Testing Overview
Added
TestAddBoundHostPortsinpkg/dockerutil/containers_internal_test.go(whitebox, package
dockerutil), covering both thePortBindings-populatedand fallback-to-
NetworkSettings.Portscases.Release/Deployment Notes
None. Pure
pkg/dockerutilchange, no image dependency.