2 years ago
#32177
McXD
TestContainers cannot connect to opened ports
In one of my tests using testcontainers, the container failed to start and the log is:
[ERROR] 17:31:38,814 [Test worker] 1.1]. - Could not start container
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (localhost ports: [49154, 49155, 49156, 49157] should be listening)
at org.testcontainers.containers.wait.strategy.HostPortWaitStrategy.waitUntilReady(HostPortWaitStrategy.java:90) ~[testcontainers-1.16.2.jar:?]
However, when I notice it took so long to start up the container, I looked at the container status:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9b52c87cf48 corda-four-nodes:0.1.1 "/bin/bash runnodes.…" 2 minutes ago Up 2 minutes 10030-10033/tcp, 0.0.0.0:49157->10010/tcp, 0.0.0.0:49156->10011/tcp, 0.0.0.0:49155->10012/tcp, 0.0.0.0:49154->10013/tcp nice_merkle
f1de539585cd testcontainers/ryuk:0.3.3 "/app" 2 minutes ago Up 2 minutes 0.0.0.0:49153->8080/tcp testcontainers-ryuk-69c9e72d-040b-4625-a82e-dbaf7d0a1cec
So clearly ports 10010-10013
have been mapped to 49154-49157
, and using netcat
, these ports are reachable, but why did the error occur and the container cannot be started?
Container definition:
@Container
@SuppressWarnings("rawtypes")
public static GenericContainer network = new GenericContainer(DockerImageName.parse(IMAGE_NAME))
.withFileSystemBind(getCordappPath(), "/nodes/Notary/cordapps", BindMode.READ_WRITE)
.withFileSystemBind(getCordappPath(), "/nodes/PartyA/cordapps", BindMode.READ_WRITE)
.withFileSystemBind(getCordappPath(), "/nodes/PartyB/cordapps", BindMode.READ_WRITE)
.withFileSystemBind(getCordappPath(), "/nodes/PartyC/cordapps", BindMode.READ_WRITE)
.withExposedPorts(10010, 10011, 10012, 10013)
.withStartupTimeout(Duration.ofSeconds(180));
(The binding works correctly)
testcontainers
testcontainers-junit5
0 Answers
Your Answer