Skip to content

Docker Compose with Docker Desktop >=3.2.0: HostPortWaitStrategy: Timed out waiting for container port to open #3923

@rogervinas

Description

@rogervinas

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions