Boris Borovski
Boris Borovski

Reputation: 144

Is there a way to pass docker flags in GenericContainer from test containers

Is there a way to pass those flags from this command in GenericContainer object from test-containers lib ?

docker container run \
   --publish 9092:9082 \
   --detach \
   --name h2 \
   nemerosa/h2

@ClassRule
public static GenericContainer h2db =
            new GenericContainer("nemerosa/h2")
             .withStartupTimeout(Duration.ofSeconds(Constants.TIMEOUT_DURATION));

Upvotes: 1

Views: 867

Answers (1)

rieckpil
rieckpil

Reputation: 12021

For exposing ports, Testcontainers offers a method on the GenericContainer:

@ClassRule
public static GenericContainer h2db =
    new GenericContainer("nemerosa/h2")
      .withExposedPorts(9092)
      .withStartupTimeout(Duration.ofSeconds(Constants.TIMEOUT_DURATION));

The --detach should be redundant as Testcontainers starts all of its containers in the background and detached.

Upvotes: 1

Related Questions