Timed out waiting for container port to open (localhost ports: [] should be listening)
See original GitHub issueHi Team,
TestContainers is unable to start Cassandra image in linux servers, however same code works fine on docker 20.10.7 in Mac.
I tried changing to use GenericContainer instead of CassandraContainer but same error. I am using TestContainers version 1.16.0 Appreciate your help here.
//dockerImage = cassandra:latest
//Cassandra_port = 9042
GenericContainer<?> cassandraContainer = new CassandraContainer<>(dockerImageName);
////GenericContainer<?> cassandraContainer = new GenericContainer<>(dockerImageName).withExposedPorts(CASSANDRA_PORT);
cassandraContainer.withExposedPorts(CASSANDRA_PORT);
////cassandraContainer.setPortBindings(List.of(String.format("%d:%d", CASSANDRA_PORT, CASSANDRA_PORT)));
cassandraContainer.start();
cassandraContainer.waitingFor(Wait.forLogMessage("Startup Complete",1));
Error -
Caused by: org.testcontainers.containers.ContainerLaunchException: Container startup failed [15:27:42] [Step 6/8] Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception [15:27:42] [Step 6/8] Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container [15:27:42] [Step 6/8] Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (localhost ports: [49329] should be listening) [15:27:42] [Step 6/8]
Docker#version
Client: Docker Engine - Community
Version: 20.10.7
API version: 1.41
Go version: go1.13.15
Git commit: f0df350
Built: Wed Jun 2 11:58:10 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:56:35 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
I recently ran into a similar issue in our Jenkins environment.
The SBDG project forks a Cassandra based Testcontainer (in the configuration of the test, here, then here), where the build itself is running inside a Docker container (see here) on Jenkins (builds).
I am not certain whether the SBDG
mainJenkins build is accessible to the outside world, but essentially, the build started failing after our sysadmin(s) upgraded to the following configuration on the Jenkins CI servers (worker nodes):I tried adding the configuration (commit) suggested by @bsideup above and that worked!
It seems the root cause of the issue is related to the Docker engine upgrade:
From:
20.10.6(20.10.6~3-0~ubuntu-bionic_amd64)To:
20.10.8(docker-ce (5:20.10.8~3-0~ubuntu-bionic)I experienced this issue with Testcontainers
1.15.3(see here).Hope this additional information helps.
Testcontainers (and the community of people) have been absolutely invaluable.
Thank you!
@jxblum thank you John for this detailed analysis! My guess would be that the memory config is what made it work, as otherwise Cassandra tried to allocate all available memory. We will release a version of Testcontainers with these optimizations soon. Meanwhile, please let us know if the problem returns with a new Docker update or something like that 😃