【问题标题】:Is there a way to pass docker flags in GenericContainer from test containers有没有办法从测试容器中传递 GenericContainer 中的 docker 标志
【发布时间】:2020-09-24 12:21:31
【问题描述】:

有没有办法从 test-containers lib 的 GenericContainer 对象中传递此命令中的这些标志?

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

【问题讨论】:

    标签: java spring-boot spring-boot-test testcontainers


    【解决方案1】:

    为了暴露端口,Testcontainers 在GenericContainer 上提供了一个方法:

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

    --detach 应该是多余的,因为 Testcontainers 在后台启动其所有容器并分离。

    【讨论】:

      猜你喜欢
      • 2019-11-06
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多