Skip to content

chore: support for deciding when to auto-export the image ports in case no exposed ports are passed #3159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

mdelapenya
Copy link
Member

  • feat: add a new config to disable exposing image ports automatically
  • chore: support for disabling auto-exposing ports from the image

What does this PR do?

This PR adds support for enabling/disabling auto-exposing the port from the container image (default is true: ports are automatically exposed).

This new setting can be configured at the properties level (using the tc.auto.expose.ports property) or with an env var (TESTCONTAINERS_AUTO_EXPOSE_PORTS).
When set to true, which is the default, the exposed ports in the image are automatically exposed to the container. When set to false, they are not.

This behavior was present in tc-java in the past (basically -P flag, publish all exposed ports), but we removed it, because it created bugs on Windows with running out of ports in a specific range over time. Given that bug is still open in Docker for Windows, we decided to not publish all ports, or at least let users configure it.

On the other hand, we are simplifying the auto-exposure of all the ports: instead of inspecting the image and merging the ports with the user request, we set the PublishAllPorts option to true in the hostConfig modifier.

Why is it important?

Simplify code, and also reduce the chances to get the bug described in docker/for-win#11584

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner May 9, 2025 10:58
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label May 9, 2025
@mdelapenya mdelapenya self-assigned this May 9, 2025
@mdelapenya mdelapenya requested review from kiview and stevenh May 9, 2025 10:58
Copy link

netlify bot commented May 9, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 9861079
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/683d6fd89e3ae80008a940a1
😎 Deploy Preview https://deploy-preview-3159--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

…ners#3161)

* feat: add a new functional option to append wait strategies to modules

* chore: update modules

* docs: make it mkore clear
* main:
  feat(couchbase): adding auth to couchbase initCluster functions to support container reuse (testcontainers#3048)
  chore(deps): bump github.com/containerd/containerd/v2 (testcontainers#3167)
  docs(options): refactor options layout in modules (testcontainers#3163)
  fix(ci): do not run sonar for Testcontainers Cloud (testcontainers#3166)
  chore(ci): do not fail fast in the Testcontainers Cloud run (testcontainers#3164)
  feat: support adding wait strategies as functional option (testcontainers#3161)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant