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


Java CreateContainerCmd.withPortBindings方法代码示例

本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerCmd.withPortBindings方法的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerCmd.withPortBindings方法的具体用法?Java CreateContainerCmd.withPortBindings怎么用?Java CreateContainerCmd.withPortBindings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.dockerjava.api.command.CreateContainerCmd的用法示例。


在下文中一共展示了CreateContainerCmd.withPortBindings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: beforeContainerCreated

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public void beforeContainerCreated(DockerAPI api, String workdir, CreateContainerCmd cmd) throws IOException, InterruptedException {

    // TODO define a strategy for SSHD process configuration so we support more than openssh's sshd
    if (cmd.getCmd() == null || cmd.getCmd().length == 0) {

        if (sshKeyStrategy.getInjectedKey() != null) {
            cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port),
                    // override sshd_config to force retrieval of InstanceIdentity public for as authentication
                    "-o", "AuthorizedKeysCommand=/root/authorized_key",
                    "-o", "AuthorizedKeysCommandUser=root"
            );
        } else {
            cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port));
        }
    }

    cmd.withPortSpecs(port+"/tcp");
    final PortBinding sshPortBinding = PortBinding.parse(":" + port);
    final Ports portBindings = cmd.getPortBindings();
    if(portBindings != null) {
        portBindings.add(sshPortBinding);
        cmd.withPortBindings(portBindings);
    } else {
        cmd.withPortBindings(sshPortBinding);
    }
    cmd.withExposedPorts(ExposedPort.parse(port+"/tcp"));
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:29,代码来源:DockerComputerSSHConnector.java

示例2: call

import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
public String call() throws Exception {
    DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null);
    
    CreateContainerCmd cfgCmd = client.createContainerCmd(imageRes);
    if (commandRes != null) {
        cfgCmd.withCmd(commandRes);
    }
    cfgCmd.withHostName(hostNameRes);
    cfgCmd.withName(containerNameRes);
    HostConfig hc = new HostConfig();
    cfgCmd.withLinks(LinkUtils.parseLinks(linksRes).getLinks());
    if (envVarsRes != null) {
        cfgCmd.withEnv(envVarsRes);
    }
    if (exposedPortsRes != null && !exposedPortsRes.isEmpty()) {
    	final ExposedPort[] ports;
        String[] exposedPortsSplitted = exposedPortsRes.split(",");
        ports = new ExposedPort[exposedPortsSplitted.length];
        for (int i = 0; i < ports.length; i++) {
            ports[i] = ExposedPort.parse(exposedPortsSplitted[i]);
        }

    	cfgCmd.withExposedPorts(ports);
    }
    if (cpuSharesRes != null) {
        cfgCmd.withCpuShares(cpuSharesRes);
    }
    if (memoryLimitRes != null) {
        cfgCmd.withMemory(memoryLimitRes);
    }
    if (dnsRes != null) {
        cfgCmd.withDns(dnsRes);
    }
    if (extraHostsRes != null) {
        cfgCmd.withExtraHosts(extraHostsRes);
    }
    if (portBindingsRes != null) {
        cfgCmd.withPortBindings(PortBindingParser.parse(portBindingsRes));
    }
    if (bindMountsRes != null) {
        cfgCmd.withBinds(BindParser.parse(bindMountsRes));
    }
    if (alwaysRestart) {
        cfgCmd.withRestartPolicy(RestartPolicy.alwaysRestart());
    }
    
    CreateContainerResponse resp = cfgCmd.withPublishAllPorts(publishAllPorts).withPrivileged(privileged).exec();
    InspectContainerResponse inspectResp = client.inspectContainerCmd(resp.getId()).exec();
    
    ObjectMapper mapper = new ObjectMapper();
    String serialized = mapper.writeValueAsString(inspectResp);
    return serialized;
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:54,代码来源:CreateContainerRemoteCallable.java


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