fix(container): expose UDP ports properly#122
Merged
mdelapenya merged 2 commits intomainfrom Nov 13, 2025
Merged
Conversation
Co-authored-by: mdelapenya <951580+mdelapenya@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Backport changes from testcontainers-go PR 3485
fix(udp): expose UDP ports properly
Nov 13, 2025
Member
|
Credits to @blueprismo |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR backports testcontainers-go PR #3485 to fix UDP port binding. The fix addresses a bug where MappedPort() always returned "0" for UDP ports instead of the actual mapped host port, making UDP services in containers unusable.
Key changes:
- Modified
mergePortBindings()to convert emptyHostPortvalues to"0"for automatic Docker port allocation - Updated existing test expectations in
lifecycle.create_test.goto reflect the fix - Added comprehensive test coverage for UDP port binding behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| container/lifecycle.create.go | Added logic to convert empty HostPort to "0" in mergePortBindings() to enable proper port allocation |
| container/lifecycle.create_test.go | Updated test expectations to reflect HostPort "0" instead of empty string |
| container/udp_port_binding_test.go | Added comprehensive tests for UDP port binding fix and regression tests for TCP |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mdelapenya
approved these changes
Nov 13, 2025
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.
What does this PR do?
Backports testcontainers-go PR #3485 to fix UDP port binding. When
nat.ParsePortSpecs()processes exposed ports like"8080/udp", it createsPortBindingwith emptyHostPort: "". Docker interprets this as "don't bind" (port 0) rather than "bind to random port".Modified
mergePortBindings()to convert emptyHostPortto"0"for automatic allocation:Before:
After:
Why is it important?
UDP services in containers were unusable -
MappedPort()always returned "0" instead of the actual host port, preventing connection establishment.Related issues
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.