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


Java Ports.bind方法代码示例

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


在下文中一共展示了Ports.bind方法的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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: toPortBindings

import com.github.dockerjava.api.model.Ports; //导入方法依赖的package包/类
private Ports toPortBindings(Collection<PortBinding> portBindings) {
    Ports ports = new Ports();
    for (PortBinding portBinding : portBindings) {
        ports.bind(
            new ExposedPort(
                portBinding.getExposedPort().getExposed(),
                InternetProtocol.parse(portBinding.getExposedPort().getType())),
            new Binding(portBinding.getHost(), Integer.toString(portBinding.getBound())));
    }
    return ports;
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:12,代码来源:DockerClientExecutor.java

示例9: verify_container_SIMPLE_create_with_ports_and_volumes_and_variables

import com.github.dockerjava.api.model.Ports; //导入方法依赖的package包/类
@Test
public void verify_container_SIMPLE_create_with_ports_and_volumes_and_variables ()
		throws Exception {

	String imageName = BUSY_BOX;
	loadImageIfNeeded( imageName );

	String containerName = "/java-simple-" + LocalDateTime.now().format( DateTimeFormatter.ofPattern( "MMM.d-HH.mm.ss" ) );
	List<String> entryParameters = Arrays.asList( "nginx", "-g", "daemon off;" );
	List<String> cmdParameters = Arrays.asList( "nginx", "-v" );

	// ref. https://github.com/docker-java/docker-java/wiki
	ExposedPort tcp80 = ExposedPort.tcp( 80 );
	List<ExposedPort> exposedList = new ArrayList<>();
	// exposedList.add( tcp80 ) ;
	// ExposedPort tcp23 = ExposedPort.tcp(23);

	Ports portBindings = new Ports();
	portBindings.bind( tcp80, Ports.Binding.bindPort( 90 ) );
	// portBindings.bind( tcp80, Ports.Binding("") );

	List<Volumes> volumes = new ArrayList<>();
	Bind javaVolumeBind = new Bind( "/opt/java", new Volume( "/java" ), AccessMode.ro, SELContext.shared );

	List<String> environmentVariables = new ArrayList<>();
	environmentVariables.add( "JAVA_HOME=/opt/java" );
	environmentVariables.add( "WORKING_DIR=/working" );
	environmentVariables.add( "JAVA_OPTS=some path" );

	List<Ulimit> ulimits = new ArrayList<>();
	ulimits.add( new Ulimit( "nofile", 1000, 1000 ) );
	ulimits.add( new Ulimit( "nproc", 10, 10 ) );

	Map<String, String> jsonLogConfig = new HashMap<>();
	jsonLogConfig.put( "max-size", "10m" );
	jsonLogConfig.put( "max-file", "2" );

	LogConfig logConfig = new LogConfig( LoggingType.JSON_FILE, jsonLogConfig );
	CreateContainerResponse container = dockerClient
		.createContainerCmd( imageName )
		.withName( containerName )
		// .withCmd( cmdParameters )
		// .withEntrypoint( entryParameters )
		.withCpusetCpus( "0-1" )
		.withLogConfig( logConfig )
		.withCpuPeriod( 400000 )
		.withMemory( 20 * CSAP.MB_FROM_BYTES )
		.withUlimits( ulimits )
		.withExposedPorts( exposedList )
		.withPortBindings( portBindings )
		.withBinds( javaVolumeBind )
		.withHostName( "peter" )
		// .withNetworkMode( "host" )
		.withEnv( environmentVariables )
		.exec();

	InspectContainerResponse containerInfo = getContainerStatus( containerName );

	ObjectNode containerInfoJson = jacksonMapper.convertValue( containerInfo, ObjectNode.class );
	logger.info( "Name: {} ,  InfoJson: \n {}", containerInfo.getName(), pp( containerInfoJson ) );

	dockerClient.startContainerCmd( container.getId() )
		.exec();

	dockerClient
		.removeContainerCmd( container.getId() )
		.withRemoveVolumes( true )
		.withForce( true )
		.exec();
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:71,代码来源:Docker_Java.java

示例10: startNginx

import com.github.dockerjava.api.model.Ports; //导入方法依赖的package包/类
private CreateContainerResponse startNginx ()
		throws InterruptedException, IOException {
	String imageName = "nginx";
	loadImageIfNeeded( imageName );
	String containerName = "/junit-nginx-"
			+ LocalDateTime.now().format( DateTimeFormatter.ofPattern( "MMM.d-HH.mm.ss" ) );

	List<String> entryParameters = Arrays.asList( "nginx", "-g", "daemon off;" );
	List<String> cmdParameters = Arrays.asList( "nginx", "-v" );

	ExposedPort exposedPort = ExposedPort.tcp( 7080 );
	List<ExposedPort> exposedList = new ArrayList<>();
	exposedList.add( exposedPort );

	Ports portBindings = new Ports();
	portBindings.bind(
		ExposedPort.tcp( 80 ),
		Ports.Binding.bindPort( exposedPort.getPort() ) );

	CreateContainerResponse createResponse = dockerClient
		.createContainerCmd( imageName )
		.withName( containerName )
		// .withCmd( cmdParameters )
		.withEntrypoint( entryParameters )
		.withExposedPorts( exposedList )
		.withPortBindings( portBindings )
		.exec();

	dockerClient
		.startContainerCmd( createResponse.getId() )
		.exec();

	Thread.sleep( 500 );
	RestTemplate springTemplate = new RestTemplate();
	String testUrl = "http://localhost:" + exposedPort.getPort();
	String response = springTemplate.getForObject( testUrl, String.class );

	logger.info( "Testing url: {} \n\t response: {}", testUrl, response );

	assertThat( response )
		.as( "welcome message" )
		.contains( "Welcome to nginx!" );

	int maxAttempts = 20;
	String startUpMessage = "GET";

	boolean foundStartMessage = waitForMessageInLogs(
		createResponse.getId(), maxAttempts, startUpMessage );

	assertThat( foundStartMessage )
		.as( "found in logs:" + startUpMessage )
		.isTrue();
	return createResponse;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:55,代码来源:Docker_Java.java

示例11: startContainer

import com.github.dockerjava.api.model.Ports; //导入方法依赖的package包/类
@Override
public Container startContainer(Environment env, Container container) throws ContainerizationException {
    DockerContainer dockerContainer = (DockerContainer) container;
    try {
        ImageConfiguration imageConf = container.getImage().getConf();
        Ports portBindings = new Ports();
        if (imageConf.getPorts() != null) {
            for (PortConfiguration port : imageConf.getPorts()) {
                ExposedPort exposedPort = new ExposedPort("tcp", port.getContainerPort());
                Ports.Binding binding = new Ports.Binding(port.getHostPort());
                portBindings.bind(exposedPort, binding);
            }
        }
        /*if (dockerContainer.getVolumes() != null) {
            for (ServiceConfiguration.VolumeInfo volumeInfo : dockerContainer.getVolumeInfos()) {
                if (volumeInfo.getHostDir() != null) {
                    binds.add(volumeInfo.getHostDir() + ":" + volumeInfo.getId() + ":rw");
                } else {
                    binds.add(volumeInfo.getId());
                }
            }
        }*/
        List<Link> links = new ArrayList<Link>();
        for (LinkConfiguration link : container.getImage().getConf().getLinks()) {
            String serviceNameInCurrentEnv = getNamingStrategy().generateContainerName(env, link.getService());
            String alias = link.getAlias();
            if (alias == null) {
                alias = link.getService();
            }
            links.add(new Link(serviceNameInCurrentEnv, alias));
        }
        getDockerClient().startContainerCmd(dockerContainer.getId())
                .withLinks(links.toArray(new Link[0]))
                //.withBinds()
                .withPortBindings(portBindings)
                .withPrivileged(imageConf.isPrivileged())
                .exec();
        InspectContainerResponse containerInspectResponse = getDockerClient().inspectContainerCmd(dockerContainer.getId()).exec();
        dockerContainer.setRunning(containerInspectResponse.getState().isRunning());
        dockerContainer.fillPortMapping(containerInspectResponse);
        fillVariables(env, imageConf, dockerContainer);
        return dockerContainer;
    } catch(Exception ex) {
        throw new ContainerizationException(ex);
    }
}
 
开发者ID:ssouporg,项目名称:denv,代码行数:47,代码来源:DockerContainerManager.java

示例12: startContainerWithConflictingPortBindings

import com.github.dockerjava.api.model.Ports; //导入方法依赖的package包/类
@Test(expected = InternalServerErrorException.class)
public void startContainerWithConflictingPortBindings() throws DockerException {

    ExposedPort tcp22 = ExposedPort.tcp(22);
    ExposedPort tcp23 = ExposedPort.tcp(23);

    Ports portBindings = new Ports();
    portBindings.bind(tcp22, Binding.bindPort(11022));
    portBindings.bind(tcp23, Binding.bindPort(11022));

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("true")
            .withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(isEmptyString()));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:20,代码来源:StartContainerCmdIT.java

示例13: startContainerWithPortBindings

import com.github.dockerjava.api.model.Ports; //导入方法依赖的package包/类
@Test
public void startContainerWithPortBindings() throws DockerException {
    int baseport = getFactoryType() == FactoryType.JERSEY? 13000: 14000;

    ExposedPort tcp22 = ExposedPort.tcp(22);
    ExposedPort tcp23 = ExposedPort.tcp(23);

    Ports portBindings = new Ports();
    portBindings.bind(tcp22, Binding.bindPort(baseport + 22));
    portBindings.bind(tcp23, Binding.bindPort(baseport + 23));
    portBindings.bind(tcp23, Binding.bindPort(baseport + 24));

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("true")
            .withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(isEmptyString()));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(Arrays.asList(inspectContainerResponse.getConfig().getExposedPorts()), contains(tcp22, tcp23));

    assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp22)[0],
            is(equalTo(Binding.bindPort(baseport + 22))));

    assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp23)[0],
            is(equalTo(Binding.bindPort(baseport + 23))));

    assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp23)[1],
            is(equalTo(Binding.bindPort(baseport + 24))));

}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:38,代码来源:StartContainerCmdIT.java

示例14: startContainerWithRandomPortBindings

import com.github.dockerjava.api.model.Ports; //导入方法依赖的package包/类
@Test
public void startContainerWithRandomPortBindings() throws DockerException {

    ExposedPort tcp22 = ExposedPort.tcp(22);
    ExposedPort tcp23 = ExposedPort.tcp(23);

    Ports portBindings = new Ports();
    portBindings.bind(tcp22, Binding.empty());
    portBindings.bind(tcp23, Binding.empty());

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999")
            .withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).withPublishAllPorts(true).exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(isEmptyString()));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(Arrays.asList(inspectContainerResponse.getConfig().getExposedPorts()), contains(tcp22, tcp23));

    assertThat(inspectContainerResponse.getNetworkSettings().getPorts().getBindings().get(tcp22)[0].getHostPortSpec(),
            is(not(equalTo(String.valueOf(tcp22.getPort())))));

    assertThat(inspectContainerResponse.getNetworkSettings().getPorts().getBindings().get(tcp23)[0].getHostPortSpec(),
            is(not(equalTo(String.valueOf(tcp23.getPort())))));

}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:31,代码来源:StartContainerCmdIT.java

示例15: createContainerWithPortBindings

import com.github.dockerjava.api.model.Ports; //导入方法依赖的package包/类
@Test
public void createContainerWithPortBindings() throws DockerException {
    int baseport = getFactoryType() == FactoryType.JERSEY? 11000: 12000;

    ExposedPort tcp22 = ExposedPort.tcp(22);
    ExposedPort tcp23 = ExposedPort.tcp(23);

    Ports portBindings = new Ports();
    portBindings.bind(tcp22, Binding.bindPort(baseport + 22));
    portBindings.bind(tcp23, Binding.bindPort(baseport + 23));
    portBindings.bind(tcp23, Binding.bindPort(baseport + 24));

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
            .withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(isEmptyString()));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(Arrays.asList(inspectContainerResponse.getConfig().getExposedPorts()), contains(tcp22, tcp23));

    assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp22)[0],
            is(equalTo(Binding.bindPort(baseport + 22))));

    assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp23)[0],
            is(equalTo(Binding.bindPort(baseport + 23))));

    assertThat(inspectContainerResponse.getHostConfig().getPortBindings().getBindings().get(tcp23)[1],
            is(equalTo(Binding.bindPort(baseport + 24))));

}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:34,代码来源:CreateContainerCmdIT.java


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