protected int readPort() throws DeploymentException { int retry = 20; Exception e = null; while (retry > 0) { try { DockerContainer utils = DockerContainer.getLast(); return utils.getPort(); } catch (Exception ex) { e = ex; } try { Thread.sleep(1000); // wait 1sec } catch (InterruptedException ie) { Thread.currentThread().interrupt(); throw new IllegalStateException(ie); } retry--; } throw new DeploymentException("Cannot read port.", e); }