testcontainers-java: NetworkMode=host causes starting issue

I use the following code to start a container:

private class CustomOracleContainer
    extends GenericContainer[CustomOracleContainer](
      DockerImageName.parse("mycompany/oracle:enterprise-19.14.0-preloaded-20220120-27-36701e3")
    )

private val oracleContainer: CustomOracleContainer = new CustomOracleContainer()
  .withExposedPorts(1521)
  .withNetworkMode("host")
  .waitingFor(Wait.forLogMessage("DATABASE IS READY TO USE!\\n", 1))
  .withStartupTimeout(Duration.ofSeconds(160))

With testcontainers 1.15.1, it works. When updating to 1.16.3, I get the following error:

ERROR ?.1.0-preloaded-20220120-27-36701e3] - Could not start container
org.testcontainers.shaded.org.awaitility.core.ConditionTimeoutException: Lambda expression in org.testcontainers.containers.GenericContainer: expected the predicate to return <true> but it returned <false> for input of <InspectContainerResponse(...))> within 5 seconds.
	at org.testcontainers.shaded.org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:164)
	at org.testcontainers.shaded.org.awaitility.core.AbstractHamcrestCondition.await(AbstractHamcrestCondition.java:86)
	at org.testcontainers.shaded.org.awaitility.core.ConditionFactory.until(ConditionFactory.java:939)
	at org.testcontainers.shaded.org.awaitility.core.ConditionFactory.until(ConditionFactory.java:645)

Any idea what’s happening ?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 22 (16 by maintainers)

Most upvoted comments

@rgugliel-da, @javahippie @pretep22, can I confirm what environments you’re on?

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

Docker docs

I’m considering whether or not to throw an exception (or at least a warning) on non-linux environments when trying to use host mode.

I use Ubuntu.

I’d like to clarify, network mode host still works as expected if not used in conjunction with withExposedPorts(). This also makes sense, because when using network mode host, there is no need to expose ports through the TC API, since the container is accessible through the host network.

Thank you, then it seems we indeed need to support the network mode. I still don’t understand why the Oracle container requires it in this setup, but since it worked in old Testcontainers versions we introduced a regression for this feature and I believe we should try to restore the fuctionality.

Situation A. From the build container, I run my JVM (sbt) and from there I start a testcontainer running Oracle