public static PortBindInfo resolvePortBindPort(CubeDockerConfiguration cubeDockerConfiguration, int exposedPort,
        String... excludedContainers) {

        final DockerCompositions dockerContainersContent = cubeDockerConfiguration.getDockerContainersContent();
        final Set<Map.Entry<String, CubeContainer>> containers = dockerContainersContent.getContainers().entrySet();

        // user specified an exposed port
        PortBindInfo portBindInfo = null;
        for (Map.Entry<String, CubeContainer> cubeContainerEntry : containers) {

            // need to skip vnc and selenium container
            if (shouldBeIgnored(cubeContainerEntry.getKey(), excludedContainers)) {
                continue;
            }

            final CubeContainer cubeContainer = cubeContainerEntry.getValue();
            final Collection<PortBinding> portBindings = cubeContainer.getPortBindings();
            if (portBindings != null) {
                for (PortBinding portBinding : portBindings) {
                    if (portBinding.getExposedPort().getExposed() == exposedPort) {
                        if (noPreviousBindPortFound(portBindInfo)) {
                            int bindPort = portBinding.getBound();
                            portBindInfo = new PortBindInfo(
                                portBinding.getExposedPort().getExposed(),
                                bindPort, cubeContainerEntry.getKey());
                        } else {
                            throw new IllegalArgumentException(
                                String.format("More than one docker container with port binding having exposed port %s.",
                                    exposedPort));
                        }
                    }
                }
            }

            if (noPreviousBindPortFound(portBindInfo)) {
                return null;
            }
        }
        return portBindInfo;
    }
public static PortBindInfo resolvePortBindPort ( CubeDockerConfiguration cubeDockerConfiguration , int exposedPort , String ... excludedContainers ) { final DockerCompositions dockerContainersContent = cubeDockerConfiguration . getDockerContainersContent ( ) ; final Set < Map . Entry < String , CubeContainer > > containers = dockerContainersContent . getContainers ( ) . entrySet ( ) ; PortBindInfo portBindInfo = null ; for ( Map . Entry < String , CubeContainer > cubeContainerEntry : containers ) { if ( shouldBeIgnored ( cubeContainerEntry . getKey ( ) , excludedContainers ) ) { continue ; } final CubeContainer cubeContainer = cubeContainerEntry . getValue ( ) ; final Collection < PortBinding > portBindings = cubeContainer . getPortBindings ( ) ; if ( portBindings != null ) { for ( PortBinding portBinding : portBindings ) { if ( portBinding . getExposedPort ( ) . getExposed ( ) == exposedPort ) { if ( noPreviousBindPortFound ( portBindInfo ) ) { int bindPort = portBinding . getBound ( ) ; portBindInfo = new PortBindInfo ( portBinding . getExposedPort ( ) . getExposed ( ) , bindPort , cubeContainerEntry . getKey ( ) ) ; } else { throw new IllegalArgumentException ( String . format ( "More than one docker container with port binding having exposed port %s." , exposedPort ) ) ; } } } } if ( noPreviousBindPortFound ( portBindInfo ) ) { return null ; } } return portBindInfo ; }
Method that tries to resolve a bind port for a given exposed port.

@param cubeDockerConfiguration
where all docker configuration is exposed
@param exposedPort
used to find the binding port
@param excludedContainers
where binding port search is ignored

@return binding port or null if couldn't be found