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


Java Ports类代码示例

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


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

示例1: defaultRunCommand

import com.github.dockerjava.api.model.Ports; //导入依赖的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

示例2: dockerCommand

import com.github.dockerjava.api.model.Ports; //导入依赖的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

示例3: dockerCommand

import com.github.dockerjava.api.model.Ports; //导入依赖的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

示例4: getBindingForPort

import com.github.dockerjava.api.model.Ports; //导入依赖的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

示例5: testPortBinding

import com.github.dockerjava.api.model.Ports; //导入依赖的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

示例6: startContainer

import com.github.dockerjava.api.model.Ports; //导入依赖的package包/类
@Override
public String startContainer(String wantedImage, Map<String, String> environment, PortBinding... portBinding) {
    Ports bindings = createPortBindings(portBinding);
    List<String> environmentStrings = createEnvironmentList(environment);
    String containerId = createContainer(wantedImage, bindings, environmentStrings);
    dockerClient.startContainerCmd(containerId).exec();
    return containerId;
}
 
开发者ID:FaustXVI,项目名称:junit5-docker,代码行数:9,代码来源:DefaultDockerClient.java

示例7: createContainer

import com.github.dockerjava.api.model.Ports; //导入依赖的package包/类
private String createContainer(String wantedImage, Ports bindings, List<String> environmentStrings) {
    String imageWithVersion = wantedImage;
    if (!imageWithVersion.contains(":")) {
        imageWithVersion += ":latest";
    }
    this.ensureImageExists(imageWithVersion);
    return dockerClient.createContainerCmd(imageWithVersion)
            .withEnv(environmentStrings)
            .withPortBindings(bindings)
            .exec().getId();
}
 
开发者ID:FaustXVI,项目名称:junit5-docker,代码行数:12,代码来源:DefaultDockerClient.java

示例8: createPortBindings

import com.github.dockerjava.api.model.Ports; //导入依赖的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

示例9: shouldStartContainerWithOnePort

import com.github.dockerjava.api.model.Ports; //导入依赖的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

示例10: createContainer

import com.github.dockerjava.api.model.Ports; //导入依赖的package包/类
public static ClosableContainer createContainer(String containerName) throws Exception {
    hostBuildDir = new File("./build/").getCanonicalPath();
    File buildLogDir = new File(hostBuildDir, "log/");
    if (!buildLogDir.exists() && !buildLogDir.mkdirs()) {
        throw new IllegalStateException("fail to create buildLogDir:" + buildLogDir);
    }

    DefaultDockerClientConfig.Builder builder
            = DefaultDockerClientConfig.createDefaultConfigBuilder().withApiVersion("1.12");
    Optional<String> dockerHostEnv = Optional.ofNullable(System.getenv("DOCKER_HOST"));
    builder.withDockerHost(dockerHostEnv.orElse("unix:///var/run/docker.sock"));

    DockerClientConfig config = builder.build();
    DockerClientBuilder dockerClientBuilder = DockerClientBuilder.getInstance(config);
    dockerClientBuilder.withDockerCmdExecFactory(new DockerCmdExecFactoryImpl());

    DockerClient dockerClient = dockerClientBuilder.build();
    ClosableContainer.removeIfExists(dockerClient, containerName);

    Ports portBindings = new Ports();
    List<ExposedPort> ports = Arrays.asList(15050, 15051, RETZ_PORT, 9999).stream()
            .map(port -> ExposedPort.tcp(port)).collect(Collectors.toList());
    ports.forEach(port -> portBindings.bind(port, Ports.Binding.bindPort(port.getPort())));

    Volume containerBuildDir = new Volume("/build");
    CreateContainerCmd createCmd = dockerClient.createContainerCmd(IMAGE_NAME)
            .withName(containerName)
            .withPrivileged(true)       // To use SystemD/Cgroups
            .withExposedPorts(ports)
            .withPortBindings(portBindings)
            .withBinds(new Bind(hostBuildDir, containerBuildDir));

    return ClosableContainer.createContainer(dockerClient, createCmd);
}
 
开发者ID:retz,项目名称:retz,代码行数:35,代码来源:IntTestBase.java

示例11: asPortBinding

import com.github.dockerjava.api.model.Ports; //导入依赖的package包/类
private Binding asPortBinding(int externalPort) {
  if (externalPort == -1) {
    return Ports.Binding.bindIp(LOCALHOST);
  }

  return Ports.Binding.bindIpAndPort(LOCALHOST, externalPort);
}
 
开发者ID:Qorr,项目名称:Hvalspik,代码行数:8,代码来源:CreateContainerCommand.java

示例12: dockerCommand

import com.github.dockerjava.api.model.Ports; //导入依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
    ExposedPort exposedPort = ExposedPort.tcp(MARATHON_PORT);
    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(MARATHON_PORT));
    }
    return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
            .withName(getName())
            .withExtraHosts("minimesos-zookeeper:" + this.zooKeeper.getIpAddress())
            .withCmd(CollectionsUtils.splitCmd(config.getCmd()))
            .withExposedPorts(exposedPort)
            .withPortBindings(portBindings);
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:15,代码来源:MarathonContainer.java

示例13: dockerCommand

import com.github.dockerjava.api.model.Ports; //导入依赖的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));
    }

    return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
        .withName(getName())
        .withExposedPorts(new ExposedPort(ZooKeeperConfig.DEFAULT_ZOOKEEPER_PORT), new ExposedPort(2888), new ExposedPort(3888))
        .withPortBindings(portBindings);
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:16,代码来源:ZooKeeperContainer.java

示例14: create

import com.github.dockerjava.api.model.Ports; //导入依赖的package包/类
@Override
public void create() {
    super.create();
    String imageId = getImageId();
    log.info("Container [" + getId() + "] : Creating container with image " + imageId);
    List<ExposedPort> exposedPorts = getExposedPorts();
    Map<Integer, Integer> portMappings = getPortsMapping();
    Ports portBindings = new Ports();
    for (ExposedPort exposedPort : exposedPorts) {
        Integer mappedPort = portMappings.get(exposedPort.getPort());
        if (mappedPort != null) {
            portBindings.bind(exposedPort, Ports.Binding.bindPort(mappedPort));
        }
    }
    String tag = getPropertyAsString("tag", "latest");
    log.info("Container [" + getId() + "] : Pulling image " + imageId);
    try {
        dockerClient.pullImageCmd(imageId).withTag(tag).exec(new PullImageResultCallback()).awaitCompletion();
    } catch (InterruptedException e) {
        throw new InvalidOperationExecutionException("Pull interrupted", e);
    }
    log.info("Container [" + getId() + "] : Pulled image " + imageId);
    CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(imageId + ":" + tag)
            .withStdinOpen(Boolean.parseBoolean(getPropertyAsString("interactive", "true")))
            .withName(DockerUtil.normalizeResourceName(config.getDeploymentName() + "_" + getId()))
            .withExposedPorts(exposedPorts.toArray(new ExposedPort[exposedPorts.size()]))
            .withPortBindings(portBindings);
    if (volumes != null && !volumes.isEmpty()) {
        createContainerCmd.withBinds(volumes.stream().map(volume -> new Bind(volume.getVolumeId(), new com.github.dockerjava.api.model.Volume(volume.getLocation()))).collect(Collectors.toList()));
    }
    List<String> commands = (List<String>) getProperty("commands");
    if (commands != null && !commands.isEmpty()) {
        createContainerCmd.withCmd(commands);
    }
    containerId = createContainerCmd.exec().getId();
    dockerExecutor = new DockerExecutor(dockerClient, containerId, Boolean.parseBoolean(getPropertyAsString("elevate_privilege")));
    log.info("Container [" + getId() + "] : Created container with id " + containerId);
}
 
开发者ID:vuminhkh,项目名称:tosca-runtime,代码行数:39,代码来源:Container.java

示例15: fillPortMapping

import com.github.dockerjava.api.model.Ports; //导入依赖的package包/类
public void fillPortMapping(InspectContainerResponse containerInspectResponse) {
    Map<Integer, Integer> portMapping = new HashMap<Integer, Integer>();
    if (containerInspectResponse.getNetworkSettings() != null && containerInspectResponse.getNetworkSettings().getPorts() != null) {
        Ports ports = containerInspectResponse.getNetworkSettings().getPorts();
        for (ExposedPort port : ports.getBindings().keySet()) {
            Ports.Binding binding = ports.getBindings().get(port);
            portMapping.put(port.getPort(), binding.getHostPort());
        }
    }
    this.setPortMapping(portMapping);
}
 
开发者ID:ssouporg,项目名称:denv,代码行数:12,代码来源:DockerContainer.java


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