com.palantir.docker.compose.DockerComposeRule.hostNetworkedPort()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中com.palantir.docker.compose.DockerComposeRule.hostNetworkedPort()方法的一些代码示例,展示了DockerComposeRule.hostNetworkedPort()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DockerComposeRule.hostNetworkedPort()方法的具体详情如下:
包路径:com.palantir.docker.compose.DockerComposeRule
类名称:DockerComposeRule
方法名:hostNetworkedPort

DockerComposeRule.hostNetworkedPort介绍

暂无

代码示例

代码示例来源:origin: palantir/atlasdb

private static InetSocketAddress connect(DockerComposeRule docker, int dbPort) {
  try {
    if (docker == null) {
      throw new IllegalStateException("Docker compose rule cannot be run, is null.");
    } else {
      docker.before();
      return InetSocketAddress.createUnresolved(
          docker.containers().ip(),
          docker.hostNetworkedPort(dbPort).getExternalPort());
    }
  } catch (IOException | InterruptedException | IllegalStateException e) {
    throw new RuntimeException("Could not run docker compose rule.", e);
  }
}

代码示例来源:origin: com.palantir.docker.compose/docker-compose-rule

public DockerPort hostNetworkedPort(int port) {
    return rule.hostNetworkedPort(port);
  }
}

代码示例来源:origin: palantir/docker-compose-rule

@Test public void
  can_access_host_networked_ports() throws Exception {
    // On linux the docker host is running on localhost, so host ports are accessible through localhost.
    // On Windows and Mac however, docker is being run in a linux VM. As such the docker host is the running
    // VM, not localhost, and the ports are inaccessible from outside the VM.
    // As such, this test will only run on linux.
    assumeTrue("Host ports are only accessible on linux", SystemUtils.IS_OS_LINUX);

    DockerComposeRule docker = DockerComposeRule.builder()
        .file("src/test/resources/host-networked-docker-compose.yaml")
        .waitingForHostNetworkedPort(5432, toBeOpen())
        .build();
    try {
      docker.before();
      assertThat(docker.hostNetworkedPort(5432).getInternalPort(), is(5432));
      assertThat(docker.hostNetworkedPort(5432).getExternalPort(), is(5432));
    } finally {
      docker.after();
    }
  }
}

相关文章