本文整理汇总了Java中com.github.dockerjava.api.model.ExposedPort.tcp方法的典型用法代码示例。如果您正苦于以下问题:Java ExposedPort.tcp方法的具体用法?Java ExposedPort.tcp怎么用?Java ExposedPort.tcp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.dockerjava.api.model.ExposedPort
的用法示例。
在下文中一共展示了ExposedPort.tcp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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;
}
示例3: 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);
}
示例4: dockerCommand
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的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);
}
示例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));
}
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);
}
示例6: dockerCommand
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
ExposedPort exposedPort = ExposedPort.tcp(SERVICE_PORT);
// port mapping is not used as port 80 is ofthen occupied on host
return DockerClientFactory.build().createContainerCmd(HELLO_WORLD_IMAGE)
.withEnv(String.format("SERVICE_%d_NAME=%s", SERVICE_PORT, SERVICE_NAME))
.withPrivileged(true)
.withName(getName())
.withExposedPorts(exposedPort);
}
示例7: toExposedPort
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的package包/类
@VsoMethod(showInApi = false)
public ExposedPort toExposedPort()
{
if(type.equals("udp"))
{
return ExposedPort.udp(portNumber);
}
else
{
return ExposedPort.tcp(portNumber);
}
}
示例8: createContainerWithPorts
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的package包/类
public String createContainerWithPorts(String image, int[] ports, String... command){
ExposedPort[] exposedPorts=new ExposedPort[ports.length];
for(int i=0;i < ports.length;i++){
exposedPorts[i]=ExposedPort.tcp(ports[i]);
}
CreateContainerResponse container = dockerClient.createContainerCmd(image)
.withCmd(command)
.withExposedPorts(exposedPorts)
.exec();
return container.getId();
}
示例9: verify_container_SIMPLE_create_with_ports_and_volumes_and_variables
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的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();
}
示例10: startNginx
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的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;
}
示例11: commitContainerHeaderTest
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的package包/类
@Test
public void commitContainerHeaderTest() {
String containerId = "9c09acd48a25";
String env = "FOO=bar";
boolean attachStdErr = true;
boolean attachStdOut = true;
boolean attachStdIn = false;
boolean disableNetwork = false;
boolean openStdIn = false;
String portSpecs = "80";
boolean stdInOnce = false;
String tag = "1.0";
String repository = "docker/empty";
String cmd = "whoami";
String author = "cameluser";
String message = "Camel Docker Container Commit";
boolean pause = false;
ExposedPorts exposedPorts = new ExposedPorts(ExposedPort.tcp(22));
Integer memory = 2048;
Integer swapMemory = 512;
String workingDir = "/opt";
String user = "docker";
Volumes volumes = new Volumes(new Volume("/example"));
boolean tty = true;
String hostname = "dockerhostname";
Map<String, Object> headers = getDefaultParameters();
headers.put(DockerConstants.DOCKER_CONTAINER_ID, containerId);
headers.put(DockerConstants.DOCKER_ENV, env);
headers.put(DockerConstants.DOCKER_ATTACH_STD_IN, attachStdIn);
headers.put(DockerConstants.DOCKER_ATTACH_STD_ERR, attachStdErr);
headers.put(DockerConstants.DOCKER_ATTACH_STD_OUT, attachStdOut);
headers.put(DockerConstants.DOCKER_DISABLE_NETWORK, disableNetwork);
headers.put(DockerConstants.DOCKER_TAG, tag);
headers.put(DockerConstants.DOCKER_REPOSITORY, repository);
headers.put(DockerConstants.DOCKER_CMD, cmd);
headers.put(DockerConstants.DOCKER_AUTHOR, author);
headers.put(DockerConstants.DOCKER_MESSAGE, message);
headers.put(DockerConstants.DOCKER_PAUSE, pause);
headers.put(DockerConstants.DOCKER_EXPOSED_PORTS, exposedPorts);
headers.put(DockerConstants.DOCKER_MEMORY, memory);
headers.put(DockerConstants.DOCKER_MEMORY_SWAP, swapMemory);
headers.put(DockerConstants.DOCKER_WORKING_DIR, workingDir);
headers.put(DockerConstants.DOCKER_USER, user);
headers.put(DockerConstants.DOCKER_VOLUMES, volumes);
headers.put(DockerConstants.DOCKER_TTY, tty);
headers.put(DockerConstants.DOCKER_HOSTNAME, hostname);
headers.put(DockerConstants.DOCKER_OPEN_STD_IN, openStdIn);
headers.put(DockerConstants.DOCKER_STD_IN_ONCE, stdInOnce);
headers.put(DockerConstants.DOCKER_PORT_SPECS, portSpecs);
template.sendBodyAndHeaders("direct:in", "", headers);
Mockito.verify(dockerClient, Mockito.times(1)).commitCmd(containerId);
Mockito.verify(mockObject, Mockito.times(1)).withEnv(env);
Mockito.verify(mockObject, Mockito.times(1)).withAttachStderr(attachStdErr);
Mockito.verify(mockObject, Mockito.times(1)).withAttachStdin(attachStdIn);
Mockito.verify(mockObject, Mockito.times(1)).withAttachStdout(attachStdOut);
Mockito.verify(mockObject, Mockito.times(1)).withDisableNetwork(disableNetwork);
Mockito.verify(mockObject, Mockito.times(1)).withTag(tag);
Mockito.verify(mockObject, Mockito.times(1)).withRepository(repository);
Mockito.verify(mockObject, Mockito.times(1)).withCmd(cmd);
Mockito.verify(mockObject, Mockito.times(1)).withAuthor(author);
Mockito.verify(mockObject, Mockito.times(1)).withMessage(message);
Mockito.verify(mockObject, Mockito.times(1)).withPause(pause);
Mockito.verify(mockObject, Mockito.times(1)).withExposedPorts(exposedPorts);
Mockito.verify(mockObject, Mockito.times(1)).withMemory(memory);
Mockito.verify(mockObject, Mockito.times(1)).withMemorySwap(swapMemory);
Mockito.verify(mockObject, Mockito.times(1)).withWorkingDir(workingDir);
Mockito.verify(mockObject, Mockito.times(1)).withUser(user);
Mockito.verify(mockObject, Mockito.times(1)).withVolumes(volumes);
Mockito.verify(mockObject, Mockito.times(1)).withTty(tty);
Mockito.verify(mockObject, Mockito.times(1)).withHostname(hostname);
Mockito.verify(mockObject, Mockito.times(1)).withOpenStdin(openStdIn);
Mockito.verify(mockObject, Mockito.times(1)).withStdinOnce(stdInOnce);
Mockito.verify(mockObject, Mockito.times(1)).withPortSpecs(portSpecs);
}
示例12: startContainerWithConflictingPortBindings
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的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();
}
示例13: startContainerWithPortBindings
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的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))));
}
示例14: startContainerWithRandomPortBindings
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的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())))));
}
示例15: createContainerWithPortBindings
import com.github.dockerjava.api.model.ExposedPort; //导入方法依赖的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))));
}