/** * Get the actual mapped port for a given port exposed by the container. * * @param originalPort the original TCP port that is exposed * @return the port that the exposed port is mapped to, or null if it is not exposed */ default Integer getMappedPort(int originalPort) { Preconditions.checkState(this.getContainerId() != null, "Mapped port can only be obtained after the container is started"); Ports.Binding[] binding = new Ports.Binding[0]; final InspectContainerResponse containerInfo = this.getContainerInfo(); if (containerInfo != null) { binding = containerInfo.getNetworkSettings().getPorts().getBindings().get(new ExposedPort(originalPort)); } if (binding != null && binding.length > 0 && binding[0] != null) { return Integer.valueOf(binding[0].getHostPortSpec()); } else { throw new IllegalArgumentException("Requested port (" + originalPort + ") is not mapped"); } }
private int getMappedPort(NetworkSettings networkSettings, int originalPort) { ExposedPort exposedPort = new ExposedPort(originalPort); Ports ports = networkSettings.getPorts(); Map<ExposedPort, Ports.Binding[]> bindings = ports.getBindings(); Ports.Binding[] binding = bindings.get(exposedPort); return Integer.valueOf(binding[0].getHostPortSpec()); } }
public Map<ExposedPort, Binding[]> getPortBindings() { return containerInfo.getNetworkSettings().getPorts().getBindings(); }
private Binding[] getPortBindings(int containerPort, Container container, DockerFacade dockerClient) { NetworkSettings networkSettings = getNetworkSettings(container, dockerClient); return networkSettings.getPorts().getBindings().get(ExposedPort.tcp(containerPort)); }
public boolean hasPortBindings() { Ports ports = containerInfo.getNetworkSettings().getPorts(); return ((ports != null) && (ports.getBindings() != null) && (!ports.getBindings().isEmpty())); }
private int getMappedPort(int exposed) { return Integer.parseInt(containerInfo.getNetworkSettings().getPorts().getBindings().get(new ExposedPort(exposed))[0].getHostPortSpec()); }
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); }
/** * Get the actual mapped port for a given port exposed by the container. * * @param originalPort the original TCP port that is exposed * @return the port that the exposed port is mapped to, or null if it is not exposed */ default Integer getMappedPort(int originalPort) { Preconditions.checkState(this.getContainerId() != null, "Mapped port can only be obtained after the container is started"); Ports.Binding[] binding = new Ports.Binding[0]; final InspectContainerResponse containerInfo = this.getContainerInfo(); if (containerInfo != null) { binding = containerInfo.getNetworkSettings().getPorts().getBindings().get(new ExposedPort(originalPort)); } if (binding != null && binding.length > 0 && binding[0] != null) { return Integer.valueOf(binding[0].getHostPortSpec()); } else { throw new IllegalArgumentException("Requested port (" + originalPort + ") is not mapped"); } }
client.startContainerCmd(ryukContainerId).exec(); InspectContainerResponse inspectedContainer = client.inspectContainerCmd(ryukContainerId).exec(); Integer ryukPort = inspectedContainer.getNetworkSettings().getPorts().getBindings().values().stream().flatMap(Stream::of).findFirst().map(Ports.Binding::getHostPortSpec).map(Integer::parseInt).get(); CountDownLatch ryukScheduledLatch = new CountDownLatch(1); synchronized (DEATH_NOTE) {
public ContainerVerificationHost setUpLocalPeerHost(String id) throws Throwable { InspectContainerResponse icr = this.dockerClient.inspectContainerCmd(id).exec(); ExposedPort exposedPort = new ExposedPort(this.containerExposedPort, this.containerProtocol); Ports.Binding binding = icr.getNetworkSettings().getPorts().getBindings().get(exposedPort)[0]; URI publicUri = UriUtils.buildUri(UriUtils.HTTP_SCHEME, binding.getHostIp(), Integer.valueOf(binding.getHostPortSpec()), null, null, null);
Ports.Binding binding = icr.getNetworkSettings().getPorts().getBindings().get(exposedPort)[0]; URI publicUri = UriUtils.buildUri(UriUtils.HTTP_SCHEME, binding.getHostIp(), Integer.valueOf(binding.getHostPortSpec()), null, null, null);