| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
getMappedPort/getFirstMappedPort used the start-time cached container inspect, so host ports became stale after Docker reassigned them (network disconnect/reconnect, and some secondary network attach scenarios). Resolve bindings from getCurrentContainerInfo() instead. Fixes testcontainers#11779
| Back | FazBrowse Home | New Git URL |
What does this PR do?
Fixes getMappedPort / getFirstMappedPort returning a stale host port after Docker reassigns published ports when networks change.
Root cause: ContainerState.getMappedPort read bindings from the start-time cached getContainerInfo(). After attaching another network (or disconnect/reconnect), Docker may publish a different host port while the cache still holds the original value — matching issue #11779.
Fix: Resolve port bindings from a live inspect via getCurrentContainerInfo() so reported host ports always match Docker's current state.
Why not only document / refresh manually?
Issue #11779 is a functional correctness bug for a common post-start network workflow. Callers of getFirstMappedPort() reasonably expect Docker's current published port. Wait strategies resolve mapped ports once before polling (not per-poll), so the extra inspect cost is bounded for typical usage.
Related change history
This PR re-applies the live-inspect approach with focused regression coverage for the #11779 scenario.
How was it tested?
Fixes #11779