本文整理汇总了Java中com.github.dockerjava.api.model.ExposedPort类的典型用法代码示例。如果您正苦于以下问题:Java ExposedPort类的具体用法?Java ExposedPort怎么用?Java ExposedPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExposedPort类属于com.github.dockerjava.api.model包,在下文中一共展示了ExposedPort类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: createContainer
import com.github.dockerjava.api.model.ExposedPort; //导入依赖的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
示例17: testWithAContainerWithTwoPorts
import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Test
public void testWithAContainerWithTwoPorts() throws InterruptedException {
CreateContainerResponse container = client.createContainerCmd("nginx")
.withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443))
.withPortBindings(PortBinding.parse("80"), PortBinding.parse("443"))
.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(2);
client.stopContainerCmd(container.getId()).exec();
done.set(false);
Future<Void> future3 = Future.future();
future3.setHandler(ar -> done.set(ar.succeeded()));
bridge.scan(future3);
await().untilAtomic(done, is(true));
assertThat(bridge.getServices()).hasSize(0);
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:37,代码来源:DockerBridgeTest.java
示例18: testWithAContainerWithLabels
import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
@Test
public void testWithAContainerWithLabels() throws InterruptedException {
Map<String, String> labels = new LinkedHashMap<>();
labels.put("service.type", "http-endpoint");
labels.put("ssl", "true");
CreateContainerResponse container = client.createContainerCmd("nginx")
.withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443))
.withPortBindings(PortBinding.parse("80"))
.withLabels(labels)
.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);
assertThat(service.records().get(0).getLocation().getString("endpoint")).startsWith("https");
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:31,代码来源:DockerBridgeTest.java
示例19: initTestContainer
import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
protected void initTestContainer()
throws Exception {
final String scenarioFileName = scenarioPath.getFileName().toString();
int dotPos = scenarioFileName.lastIndexOf('.');
if(dotPos > 0) {
final String scenarioFileExt = scenarioFileName.substring(dotPos + 1);
final String dockerImageName = SCENARIO_LANG_IMAGES.get(scenarioFileExt);
if(dockerImageName == null) {
fail();
}
System.out.println("docker pull " + dockerImageName + "...");
dockerClient.pullImageCmd(dockerImageName)
.exec(new PullImageResultCallback())
.awaitSuccess();
final List<String> cmd = new ArrayList<>();
cmd.add("-Xms1g");
cmd.add("-Xmx1g");
cmd.add("-XX:MaxDirectMemorySize=1g");
cmd.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
cmd.add("-Dcom.sun.management.jmxremote=true");
cmd.add("-Dcom.sun.management.jmxremote.port=9010");
cmd.add("-Dcom.sun.management.jmxremote.rmi.port=9010");
cmd.add("-Dcom.sun.management.jmxremote.local.only=false");
cmd.add("-Dcom.sun.management.jmxremote.authenticate=false");
cmd.add("-Dcom.sun.management.jmxremote.ssl=false");
cmd.add("-jar");
cmd.add("/opt/mongoose/mongoose.jar");
cmd.addAll(configArgs);
final StringJoiner cmdLine = new StringJoiner(" ");
cmd.forEach(cmdLine::add);
System.out.println("Container arguments: " + cmdLine.toString());
final Volume volumeShare = new Volume(CONTAINER_SHARE_PATH);
final Volume volumeLog = new Volume(CONTAINER_LOG_PATH);
final Bind[] binds = new Bind[] {
new Bind(HOST_SHARE_PATH.toString(), volumeShare),
new Bind(HOST_LOG_PATH.toString(), volumeLog),
};
// put the environment variables into the container
final Map<String, String> envMap = System.getenv();
final String[] env = envMap.keySet().toArray(new String[envMap.size()]);
for(int i = 0; i < env.length; i ++) {
if("PATH".equals(env[i])) {
env[i] = env[i] + "=" + envMap.get(env[i]) + ":/bin";
} else {
env[i] = env[i] + "=" + envMap.get(env[i]);
}
}
final CreateContainerResponse container = dockerClient
.createContainerCmd(dockerImageName)
.withName("mongoose")
.withNetworkMode("host")
.withExposedPorts(ExposedPort.tcp(9010), ExposedPort.tcp(5005))
.withVolumes(volumeShare, volumeLog)
.withBinds(binds)
.withAttachStdout(true)
.withAttachStderr(true)
.withEnv(env)
.withEntrypoint("mongoose")
.withCmd(cmd)
.exec();
testContainerId = container.getId();
dockerClient
.attachContainerCmd(testContainerId)
.withStdErr(true)
.withStdOut(true)
.withFollowStream(true)
.exec(streamsCallback);
} else {
fail();
}
}
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:80,代码来源:ScenarioTestBase.java
示例20: getPortBindings
import com.github.dockerjava.api.model.ExposedPort; //导入依赖的package包/类
private Map<ExposedPort, Binding[]> getPortBindings(Container container) {
NetworkSettings networkSettings = getNetworkSettings(container);
if (networkSettings.getPorts() == null) {
LOG.debug("No ports");
return new HashMap<>();
}
return networkSettings.getPorts().getBindings();
}
开发者ID:Qorr,项目名称:Hvalspik,代码行数:10,代码来源:BindPortsAction.java
注:本文中的com.github.dockerjava.api.model.ExposedPort类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论