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 5 years ago
  • Reactions: 3
  • Comments: 23 (2 by maintainers)

Most upvoted comments

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

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

@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.

Same issue on Mac M3, Sonoma 14.4, with testcontainer 1.17.2, Colima 0.7.0 for docker and Spring Boot 2.15 + Cucumber. This happens sporadically. Someone pointed out this is not a testcontainer issue but rather a Docker one - so I am looking for a workaround.

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.

Running into the same problem. Did anyone else on here find a workaround for this ?

Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (localhost ports: [32802] should be listening) at org.testcontainers.containers.wait.strategy.HostPortWaitStrategy.waitUntilReady(HostPortWaitStrategy.java:112) at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52) at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:909) at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:500) ... 34 more

I’m using Rancher Desktop version: 1.12.1 Running on a Mac with an M2 Pro chip, on Sonoma 14.5 testcontainers version: 1.20.1 Docker Version:

Client:
 Version:           24.0.7-rd
 API version:       1.42 (downgraded from 1.43)
 Go version:        go1.20.10
 Git commit:        72ffacf
 Built:             Wed Nov  1 18:41:50 2023
 OS/Arch:           darwin/arm64
 Context:           default

Server:
 Engine:
  Version:          23.0.6
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.20.11
  Git commit:       9dbdbd4b6d7681bd18c897a6ba0376073c2a72ff
  Built:            Fri Nov 17 20:59:57 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          v1.7.2
  GitCommit:        0cae528dd6cb557f7201036e9f43420650207b58
 runc:
  Version:          1.1.7
  GitCommit:        860f061b76bb4fc671f0f9e900f7d80ff93d4eb7
 docker-init:
  Version:          0.19.0
  GitCommit:      

Further debugging: I created a simple app to test with and tested in the build agent this keeps failing in (continued to fail), and then a plain docker-in-docker image published by docker, and it succeeded. I then tried creating a fresh clone of the agent container and it worked. Pulling my hair out, I service docker restart and everything is working again. I had recreated that container multiple times up until that point and it never worked, I still have no idea what was causing the issue.

That’s worked for me.

@SpringBootTest
@Sql("/datasets/truncate_all_tables.sql")
public abstract class AbstractIntegrationTests {

    public AbstractIntegrationTests() {
        final GenericContainer<?> postgres = new GenericContainer<>(DockerImageName.parse("postgres:13.2-alpine"))
                .withEnv("POSTGRES_USER", "accessmanager")
                .withEnv("POSTGRES_PASSWORD", "accessmanager")
                .withEnv("POSTGRES_DB", "accessmanager");
        postgres.setPortBindings(Collections.singletonList(String.format("%d:%d/%s", 5433, 5432, InternetProtocol.TCP.toDockerNotation())));
        try {
            postgres.start();
        } catch (final Exception ignore) {
        }
    }
}


public class GroupPermissionRepositoryTests extends AbstractIntegrationTests {

    @Autowired
    private GroupRepository groupRepository;
    @Autowired
    private PermissionRepository permissionRepository;
    @Autowired
    private GroupPermissionRepository groupPermissionRepository;

    private final Group group = new Group();
    private Permission rootPermission;

    @BeforeEach
    void setUp() {
        group.setName("Access Group Name");
        groupRepository.save(group);
        rootPermission = permissionRepository.findById(1L).orElseThrow();
    }

    @Test
    public void mustListGroupsPermissionsByGroupId() {
        System.out.println(" ------ ");
        final GroupPermission groupPermission = new GroupPermission();
        groupPermission.setPermission(rootPermission);
        groupPermission.setGroup(group);
        groupPermissionRepository.save(groupPermission);

        final List<GroupPermission> groupsPermissionsSaved = groupPermissionRepository.listByGroupId(group.getId());

        System.out.println(groupsPermissionsSaved.size());
    }

}

@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.

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…