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

梦想的初衷 提交于 2020-06-29 04:31:25

问题


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));

回答1:


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.



来源:https://stackoverflow.com/questions/62212879/is-there-a-way-to-pass-docker-flags-in-genericcontainer-from-test-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!