code: public static String getRunningDockerContainerId( Session session, String containerName ) throws JSchException, IOException {
          String command = "docker ps | grep " + containerName;
          String remoteResponseStr = launchACommand(session, command);
          if (remoteResponseStr.length() == 0) {
              return null;
          }
  
          List<String> containerIdsList = new ArrayList<>();
          String[] linesSplit = remoteResponseStr.split("\n");
          for( String line : linesSplit ) {
              String[] psSplit = line.split("\\s+");
              if (psSplit.length < 3) {
                  throw new JSchException("Could not retrieve container data. Result was: " + line);
              }
              String cid = psSplit[0];
              containerIdsList.add(cid);
          }
          if (containerIdsList.size() > 1) {
              throw new JSchException("More than one container was identified with the given filters. Check your filters.");
          } else if (containerIdsList.size() == 0) {
              return null;
          }
          return containerIdsList.get(0);
      }
docs: Get the container id of a running docker container.
  
  @param session the session to use.
  @param containerName the name of the container, used in a grep filter.
  @return the id of the container or null.
  @throws JSchException
  @throws IOException