Problem
It has previously been brought up multiple times across the testcontainers SDKs (eg. #386) that the host port for a container can suddenly change right after the container has started. This causes tests to sometimes pass and sometimes fail, depending on what happened before; port changing or connection to the container from the host.
The underlying issue here seems to be moby/moby#42442 , which has been open since 2021 without being fixed. It thus only happens on some systems and not all.
Solution
Since the many projects already decided to work around this issue by using testcontainers in a way that specifically selects an open port instead of auto-assigning a high random port (Kong/kubernetes-ingress-controller#5005 for example), I suggest making a permanent workaround as a feature in the .NET SDK. It can be automatic behind the scenes, or opt-in.
Benefit
The project won't randomly fail tests on ipv6 enabled clients.
Alternatives
Probably, I'm not too familiar with this project yet.
Would you like to help contributing this enhancement?
No