当前位置: 首页>>代码示例>>Java>>正文


Java ExposedPort类代码示例

本文整理汇总了Java中com.github.dockerjava.api.model.ExposedPort的典型用法代码示例。如果您正苦于以下问题:Java ExposedPort类的具体用法?Java ExposedPort怎么用?Java ExposedPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExposedPort类属于com.github.dockerjava.api.model包,在下文中一共展示了ExposedPort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startDockerNoVnc

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
private int startDockerNoVnc() {
    String novncImage = getString("sel.jup.novnc.image");
    dockerService.pullImageIfNecessary(novncImage);

    int novncPort = dockerService.findRandomOpenPort();
    Binding novncBindPort = bindPort(novncPort);
    ExposedPort novncExposedPort = tcp(getInt("sel.jup.novnc.port"));
    List<PortBinding> portBindings = asList(
            new PortBinding(novncBindPort, novncExposedPort));
    String novncContainerName = dockerService
            .generateContainerName("novnc");
    DockerContainer novncContainer = DockerContainer
            .dockerBuilder(novncImage, novncContainerName)
            .portBindings(portBindings).build();
    dockerService.startAndWaitContainer(novncContainer);
    containers.put(novncContainerName, novncImage);

    return novncPort;
}
 
开发者ID:bonigarcia,项目名称:selenium-jupiter,代码行数:20,代码来源:DockerDriverHandler.java

示例2: testWithAContainerWithAPort

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Test
public void testWithAContainerWithAPort() throws InterruptedException {
  CreateContainerResponse container = client.createContainerCmd("nginx")
      .withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443))
      .withPortBindings(PortBinding.parse("80"))
      .exec();

  AtomicBoolean done = new AtomicBoolean();
  Future<Void> future = Future.future();
  future.setHandler(ar -> done.set(ar.succeeded()));
  bridge.scan(future);
  await().untilAtomic(done, is(true));
  assertThat(bridge.getServices()).hasSize(0);

  done.set(false);
  client.startContainerCmd(container.getId()).exec();
  Future<Void> future2 = Future.future();
  future2.setHandler(ar -> done.set(ar.succeeded()));
  bridge.scan(future2);
  await().untilAtomic(done, is(true));

  assertThat(bridge.getServices()).hasSize(1);
  DockerService service = bridge.getServices().get(0);
  assertThat(service.records()).hasSize(1);
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:26,代码来源:DockerBridgeTest.java

示例3: run

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Override
public void run(Container container, Spec spec) {
  Map<ExposedPort, Binding[]> bindingMap = getPortBindings(container);

  bindingMap.forEach((port, bindings) -> {
    int internalPort = port.getPort();

    if (bindings == null) {
      return;
    }

    for (Binding binding : bindings) {
      String ipAddress = binding.getHostIp();
      if (ipAddress.equals(DEFAULT_BINDING)) {
        ipAddress = dockerClient.hostInfo().getIpAddress();
      }
      container.addExposedPort(new ContainerPort(ipAddress, binding.getHostPortSpec(), internalPort));
    }
  });
}
 
开发者ID:Qorr,项目名称:Hvalspik,代码行数:21,代码来源:BindPortsAction.java

示例4: defaultRunCommand

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Override
public void defaultRunCommand(String eclipseProjectName, String dockerBuildContext) {
    ExposedPort tcp8080 = ExposedPort.tcp(8080);

    CreateContainerResponse container = dockerClient.createContainerCmd("mariolet/my-tomcat")
       .withCmd("true")
       .withExposedPorts(tcp8080)
       .exec();

    Ports portBindings = new Ports();
    portBindings.bind(tcp8080, Ports.Binding(80));

    dockerClient.startContainerCmd(container.getId())
       .withPortBindings(portBindings)
       .exec();
}
 
开发者ID:domeide,项目名称:doclipser,代码行数:17,代码来源:DockerClientJavaApi.java

示例5: dockerCommand

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
    int port = getServicePort();
    ExposedPort exposedPort = ExposedPort.tcp(port);

    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
    }

    CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag())
        .withName(getName())
        .withExposedPorts(new ExposedPort(getServicePort()))
        .withEnv(newEnvironment()
            .withValues(getMesosMasterEnvVars())
            .withValues(getSharedEnvVars())
            .createEnvironment())
        .withPortBindings(portBindings);

    MesosDns mesosDns = getCluster().getMesosDns();
    if (mesosDns != null) {
        cmd.withDns(mesosDns.getIpAddress());
    }

    return cmd;
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:27,代码来源:MesosMasterContainer.java

示例6: dockerCommand

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
    int port = getServicePort();
    ExposedPort exposedPort = ExposedPort.tcp(port);

    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
    }

    ExposedPort consulHTTPPort = ExposedPort.tcp(ConsulConfig.CONSUL_HTTP_PORT);
    ExposedPort consulDNSPort = ExposedPort.udp(ConsulConfig.CONSUL_DNS_PORT);

    return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
            .withName(getName())
            .withCmd("agent", "-server", "-bootstrap", "-client", "0.0.0.0")
            .withExposedPorts(consulHTTPPort, consulDNSPort)
            .withPortBindings(portBindings);
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:20,代码来源:ConsulContainer.java

示例7: exportPortBindings

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
private void exportPortBindings(EnvVars envs, Map<ExposedPort, Binding[]> bindings) {
	StringBuilder ports = new StringBuilder();
	for (ExposedPort exposedPort : bindings.keySet()) {
		ports.append(exposedPort.toString()).append(ID_SEPARATOR);
		Binding[] exposedPortBinding = bindings.get(exposedPort);
		if (exposedPortBinding == null) {
			continue;
		}
		envs.put(PORT_BINDING_PREFIX + exposedPort.getProtocol().name() + "_" + exposedPort.getPort(),
				exposedPortBinding[0].getHostPortSpec());

		StringBuilder portBinding = new StringBuilder();
		String hostIp = exposedPortBinding[0].getHostIp();
		if (hostIp != null && hostIp.length() > 0) {
			portBinding.append(hostIp).append(":");
			portBinding.append(exposedPortBinding[0].getHostPortSpec());
			envs.put(HOST_SOCKET_PREFIX + exposedPort.getProtocol().name() + "_" + exposedPort.getPort(),
					portBinding.toString());
		}
	}
	String bindPorts = ports.substring(0, ports.length() - 1).toString();
	envs.put(PORT_BINDINGS_ENV_VAR, bindPorts);
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:24,代码来源:DockerEnvContributor.java

示例8: setExposed

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
private void setExposed(Instance instance, ExposedPort[] exposedPorts) {
    if (exposedPorts == null || exposedPorts.length == 0) {
        return;
    }

    List<String> expose = fieldStringList(instance, InstanceConstants.FIELD_EXPOSE);
    boolean modified = false;
    for (ExposedPort ep : exposedPorts) {
        String key = ep.getPort() + "/" + (ep.getProtocol() == null ? "tcp" : ep.getProtocol().toString());
        if (!expose.contains(key)) {
            expose.add(key);
            modified = true;
        }
    }

    if (modified) {
        setField(instance, FIELD_EXPOSE, expose);
    }
}
 
开发者ID:rancher,项目名称:cattle,代码行数:20,代码来源:DockerTransformerImpl.java

示例9: resolveExposedPorts

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
private Set<ExposedPort> resolveExposedPorts(CubeContainer containerConfiguration,
    CreateContainerCmd createContainerCmd) {
    Set<ExposedPort> allExposedPorts = new HashSet<>();
    if (containerConfiguration.getPortBindings() != null) {
        for (PortBinding binding : containerConfiguration.getPortBindings()) {
            allExposedPorts.add(new ExposedPort(binding.getExposedPort().getExposed(),
                InternetProtocol.parse(binding.getExposedPort().getType())));
        }
    }
    if (containerConfiguration.getExposedPorts() != null) {
        for (org.arquillian.cube.docker.impl.client.config.ExposedPort port : containerConfiguration.getExposedPorts()) {
            allExposedPorts.add(new ExposedPort(port.getExposed(), InternetProtocol.parse(port.getType())));
        }
    }
    return allExposedPorts;
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:17,代码来源:DockerClientExecutor.java

示例10: hasExposedPorts

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
public ContainerAssert hasExposedPorts(String... ports) {
    isNotNull();

    List<ExposedPort> exposedPorts = new ArrayList<ExposedPort>();
    for (String port : ports) {
        exposedPorts.add(ExposedPort.parse(port));
    }

    ExposedPort[] myports = new ExposedPort[exposedPorts.size()];
    exposedPorts.toArray(myports);

    assertThat(getContainerConfig().getExposedPorts())
        .overridingErrorMessage("%nExpecting:%n <%s>%nto contain:%n <%s>", getContainerConfig().getExposedPorts(),
            Arrays.asList(ports))
        .contains(myports);

    return this;
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:19,代码来源:ContainerAssert.java

示例11: hasBindPorts

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
public ContainerAssert hasBindPorts(String... ports) {
    isNotNull();

    List<ExposedPort> exposedPorts = new ArrayList<ExposedPort>();
    for (String port : ports) {
        exposedPorts.add(ExposedPort.parse(port));
    }

    ExposedPort[] myports = new ExposedPort[exposedPorts.size()];
    exposedPorts.toArray(myports);

    assertThat(getHostConfig().getPortBindings().getBindings())
        .overridingErrorMessage("%nExpecting:%n <%s>%nto contain:%n <%s>",
            getHostConfig().getPortBindings().getBindings().keySet(), Arrays.asList(ports))
        .containsKeys(myports);

    return this;
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:19,代码来源:ContainerAssert.java

示例12: getBindingForPort

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
private InetSocketAddress getBindingForPort(DockerAPI api, InspectContainerResponse ir, int internalPort) {
    // get exposed port
    ExposedPort sshPort = new ExposedPort(internalPort);
    Integer port = 22;

    final NetworkSettings networkSettings = ir.getNetworkSettings();
    final Ports ports = networkSettings.getPorts();
    final Map<ExposedPort, Ports.Binding[]> bindings = ports.getBindings();

    // Get the binding that goes to the port that we're interested in (e.g: 22)
    final Ports.Binding[] sshBindings = bindings.get(sshPort);

    // Find where it's mapped to
    for (Ports.Binding b : sshBindings) {
        String hps = b.getHostPortSpec();
        port = Integer.valueOf(hps);
    }
    String host = getExternalIP(api, ir, networkSettings, sshBindings);

    return new InetSocketAddress(host, port);
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:22,代码来源:DockerComputerSSHConnector.java

示例13: testPortBinding

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Test
public void testPortBinding() throws IOException, InterruptedException {
    DockerComputerSSHConnector connector = new DockerComputerSSHConnector(Mockito.mock(DockerComputerSSHConnector.SSHKeyStrategy.class));
    CreateContainerCmdImpl cmd = new CreateContainerCmdImpl(Mockito.mock(CreateContainerCmd.Exec.class), "");
    cmd.withPortBindings(PortBinding.parse("42:42"));

    connector.setPort(22);
    connector.beforeContainerCreated(Mockito.mock(DockerAPI.class), "/workdir", cmd);
    final Ports portBindings = cmd.getPortBindings();
    Assert.assertNotNull(portBindings);
    final Map<ExposedPort, Ports.Binding[]> bindingMap = portBindings.getBindings();
    Assert.assertNotNull(bindingMap);
    Assert.assertEquals(2, bindingMap.size());

    final Ports.Binding[] configuredBindings = bindingMap.get(new ExposedPort(42));
    Assert.assertNotNull(configuredBindings);
    Assert.assertEquals(1, configuredBindings.length);
    Assert.assertEquals("42", configuredBindings[0].getHostPortSpec());

    final Ports.Binding[] sshBindings = bindingMap.get(new ExposedPort(22));
    Assert.assertNotNull(sshBindings);
    Assert.assertEquals(1, sshBindings.length);
    Assert.assertNull(sshBindings[0].getHostPortSpec());

    System.out.println();
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:27,代码来源:DockerComputerSSHConnectorTest.java

示例14: createPortBindings

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
private Ports createPortBindings(PortBinding... portBinding) {
    Ports bindings = new Ports();
    for (PortBinding binding : portBinding) {
        ExposedPort inner = tcp(binding.inner);
        bindings.bind(inner, bindPort(binding.exposed));
    }
    return bindings;
}
 
开发者ID:FaustXVI,项目名称:junit5-docker,代码行数:9,代码来源:DefaultDockerClient.java

示例15: shouldStartContainerWithOnePort

import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Test
@DisplayName("start a container with one port")
public void shouldStartContainerWithOnePort() {
    String containerId = defaultDockerClient.startContainer(WANTED_IMAGE, emptyMap(),
        new PortBinding(8081, 8080));
    InspectContainerResponse startedContainer = dockerClient.inspectContainerCmd(containerId).exec();
    Ports ports = startedContainer.getHostConfig().getPortBindings();
    assertThat(ports).isNotNull();
    Map<ExposedPort, Ports.Binding[]> portBindings = ports.getBindings();
    assertThat(portBindings).hasSize(1)
        .containsKeys(new ExposedPort(8080));
    assertThat(portBindings.get(new ExposedPort(8080))).hasSize(1)
        .extracting(Ports.Binding::getHostPortSpec)
        .contains("8081");
}
 
开发者ID:FaustXVI,项目名称:junit5-docker,代码行数:16,代码来源:DefaultDockerClientIT.java


注:本文中的com.github.dockerjava.api.model.ExposedPort类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。