code: private DockerCLI createCliWithWait(URL url, int port) throws InterruptedException, IOException {
          DockerCLI tempCli = null;
          boolean connected = false;
          int i = 0;
          while (i <= 10 && !connected) {
              i++;
              try {
                  final CLIConnectionFactory factory = new CLIConnectionFactory().url(url);
                  tempCli = new DockerCLI(factory, port);
                  final String channelName = tempCli.getChannel().getName();
                  if (channelName.contains("CLI connection to")) {
                      tempCli.upgrade();
                      connected = true;
                      LOG.debug(channelName);
                  } else {
                      LOG.debug("Cli connection is not via CliPort '{}'. Sleeping for 5s...", channelName);
                      tempCli.close();
                      Thread.sleep(5 * 1000);
                  }
              } catch (IOException e) {
                  LOG.debug("Jenkins is not available. Sleeping for 5s...", e.getMessage());
                  Thread.sleep(5 * 1000);
              }
          }
  
          if (!connected) {
              throw new IOException("Can't connect to {}" + url.toString());
          }
  
          LOG.info("Jenkins future {}", url);
          LOG.info("Jenkins future {}/configure", url);
          LOG.info("Jenkins future {}/log/all", url);
          return tempCli;
      }
docs: Create DockerCLI connection against specified jnlpSlaveAgent port