testcontainers-go
testcontainers-go copied to clipboard
chore: support for deciding when to auto-export the image ports in case no exposed ports are passed
- 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 https://github.com/docker/for-win/issues/11584
Related issues
- Related to https://github.com/docker/for-win/issues/11584