Upgrading to Docker Desktop 3.2.2 our tests using DockerComposeContainer started to fail when using docker-compose with dynamic ports. The error message is something like:
Timed out waiting for container port to open (localhost ports: [0, 55196] should be listening)
Debugging the code you can see that port 0 is reported and then ExternalPortListeningCheck fails because it tries to open a connection to localhost:0
As a workaround we are using this fix for HostPortWaitStrategy:
class HostPortWaitStrategyFixForDockerDesktop322 : HostPortWaitStrategy() {
override fun getLivenessCheckPorts(): MutableSet<Int> {
return super.getLivenessCheckPorts().stream()
.filter { port -> port > 0 }
.collect(Collectors.toSet())
}
}
And we use it like this:
container.withExposedService(SERVICE, SERVICE_PORT, HostPortWaitStrategyFixForDockerDesktop322())
hey @rogervinas, this might solve your issue #3948
@rogervinas, @wrover thanks - this bug actually causes Testcontainers' own test suite to fail with Docker for Mac >3.1.0. It looks like a pretty dramatic change was introduced in 3.2.0 - I _think_ this is the cause:
Fixed an issue when binding ports on specific IPs. Note: It may now take a bit of time before the docker inspect command shows the open ports. Fixes docker/for-mac#4541
Because ExternalPortListeningCheck receives the external ports at creation time, only the first inspect results are ever read.
I think #3948 is probably a good quick fix, but I think a general rethink of how and when ports are resolved is required - as hinted at by #3949.
Fixed in #3979
@rnorth I'm on Docker Desktop 3.3.3 and experience this on testcontainers 1.15.3. Should I open a new issue?
@dreis2211 yes please. FWIW again it seems there are numerous issues with Docker for Mac >3.
We're seeing our own test suite taking 30% longer between Docker for a Mac 2.5 and 3.3.3 - the networking performance issues could be affecting your build and causing timeouts.
Most helpful comment
hey @rogervinas, this might solve your issue #3948