code: public static String getContainerName(String hostname,
        boolean serviceRequired) throws IOException {
      int i = hostname.lastIndexOf(".");
      if (i <= 0) {
        if (serviceRequired) {
          throw badHostName(hostname);
        }
        return hostname;
      }
      return hostname.substring(0, i);
    }
docs: Extracts container name from the container.service or container
  
  @param hostname hostname to split
  @param serviceRequired flag if service name required as part of hostname
  @return the container
  @throws IOException if hostname is invalid