public int getExposedPortFromDocker(String serviceName, int internalPort) { Sleeper sleeper = new Sleeper(); String dockerJson = null; List<String> command = of("bash", "-c", "docker inspect `docker ps | grep -w '" + internalPort + "/tcp' | cut -f 1 -d ' '`"); int count = 0; while (count < 60) { dockerJson = processUtil.runProcess(command); if (dockerJson.startsWith("[")) { break; } else { sleeper.sleepNoException(1000); } count++; } int retval = -1; if (dockerJson != null && dockerJson.startsWith("[")) { retval = parseExposedPort(dockerJson, internalPort); } if (retval == -1) { logger.error("Could not determine host port mapping for {}, is it configured " + "for port {} internally, and also exposed?", serviceName, internalPort); } return retval; }