testcontainers-java: Timed out waiting for container port to open

#3923 is still reproducible with com.playtika.testcontainers:embedded-keycloak:2.0.8 even after forcibly upgrade org.testcontainers:testcontainers transitive dependency to 1.15.3, getting

Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (localhost ports: [49187] should be listening)
	at org.testcontainers.containers.wait.strategy.HostPortWaitStrategy.waitUntilReady(HostPortWaitStrategy.java:49)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:35)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:892)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:440)
	... 104 more

Docker For Windows 3.3.3

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 20 (2 by maintainers)

Most upvoted comments

import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName

open class KGenericContainer(image: String) : GenericContainer<KGenericContainer>(DockerImageName.parse(image))

fun main() {
    val container = KGenericContainer("MY_CONTAINER")
        .withExposedPorts(8081)
    container.start()
}
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (localhost ports: [62362] should be listening)
	at org.testcontainers.containers.wait.strategy.HostPortWaitStrategy.waitUntilReady(HostPortWaitStrategy.java:49)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:35)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:923)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:466)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:329)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:327)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:315)

macbook m1 chip macOS 11.6 docker desktop 4.1.1 docker engine 20.10.8 testcontainers 1.16.0

How do you “close” this issue, it keeps happening with random versions of Docker engine and docker desktop.

@DJ-Glock can you please try out if it works with the basic example from our reproducer? https://github.com/testcontainers/testcontainers-java-repro

Also, please follow up in issue #4602, this issue has been closed by the original author and had a different cause.

@schowdiah since the issue is caused by Docker for Windows and not Testcontainers, consider reporting it to the Docker team. We do our best on the Testcontainers side to make things work but some issues (usually related to Docker) are out of our control, unfortunately.

After upgrading to the latest Docker Desktop 3.4.0 (with Docker Engine 20.10.7 that contains this fix ) and explicitly setting embedded keycloak db vendor to h2 as advised here, I don’t experience this issue anymore. Not sure which one of above changes solved the issue though…

Also seeing this exact issue with testcontainers version 1.15.3 and Docker Desktop for Mac, version 3.3.3. Also believe docker engine 20.x to be the cause. Our tests pass on Jenkins build with the older 19.03.11 docker engine.