Java Code Examples for com.github.dockerjava.api.model.ExposedPort#tcp()
The following examples show how to use
com.github.dockerjava.api.model.ExposedPort#tcp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockerClientJavaApi.java From doclipser with Eclipse Public License 1.0 | 6 votes |
@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(); }
Example 2
Source File: MesosMasterContainer.java From minimesos with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: ConsulContainer.java From minimesos with Apache License 2.0 | 6 votes |
@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); }
Example 4
Source File: StartContainerCmdIT.java From docker-java with Apache License 2.0 | 6 votes |
@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).withHostConfig(newHostConfig() .withPortBindings(portBindings)) .exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(is(emptyString()))); dockerRule.getClient().startContainerCmd(container.getId()).exec(); }
Example 5
Source File: MarathonContainer.java From minimesos with Apache License 2.0 | 5 votes |
@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); }
Example 6
Source File: ZooKeeperContainer.java From minimesos with Apache License 2.0 | 5 votes |
@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); }
Example 7
Source File: HelloWorldContainer.java From minimesos with Apache License 2.0 | 5 votes |
@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); }
Example 8
Source File: DockerConnector.java From cloudml with GNU Lesser General Public License v3.0 | 5 votes |
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(); }
Example 9
Source File: BesuNode.java From ethsigner with Apache License 2.0 | 4 votes |
private PortBinding httpRpcPortBinding() { return new PortBinding(new Binding(null, null), ExposedPort.tcp(DEFAULT_HTTP_RPC_PORT)); }
Example 10
Source File: BesuNode.java From ethsigner with Apache License 2.0 | 4 votes |
private PortBinding wsRpcPortBinding() { return new PortBinding(new Binding(null, null), ExposedPort.tcp(DEFAULT_WS_RPC_PORT)); }
Example 11
Source File: StartContainerCmdIT.java From docker-java with Apache License 2.0 | 3 votes |
@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).withHostConfig(newHostConfig() .withPortBindings(portBindings) .withPublishAllPorts(true)) .exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(is(emptyString()))); 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()))))); }