public JibContainer containerize(Containerizer containerizer)
      throws InterruptedException, RegistryException, IOException, CacheDirectoryCreationException,
          ExecutionException {
    try (BuildContext buildContext = toBuildContext(containerizer);
        TimerEventDispatcher ignored =
            new TimerEventDispatcher(
                buildContext.getEventHandlers(), containerizer.getDescription())) {
      logSources(buildContext.getEventHandlers());

      BuildResult buildResult = containerizer.run(buildContext);
      return JibContainer.from(buildContext, buildResult);

    } catch (ExecutionException ex) {
      // If an ExecutionException occurs, re-throw the cause to be more easily handled by the user
      if (ex.getCause() instanceof RegistryException) {
        throw (RegistryException) ex.getCause();
      }
      throw ex;
    }
  }
Builds the container.

@param containerizer the {@link Containerizer} that configures how to containerize
@return the built container
@throws IOException if an I/O exception occurs
@throws CacheDirectoryCreationException if a directory to be used for the cache could not be
    created
@throws HttpHostConnectException if jib failed to connect to a registry
@throws RegistryUnauthorizedException if a registry request is unauthorized and needs
    authentication
@throws RegistryAuthenticationFailedException if registry authentication failed
@throws UnknownHostException if the registry does not exist
@throws InsecureRegistryException if a server could not be verified due to an insecure
    connection
@throws RegistryException if some other error occurred while interacting with a registry
@throws ExecutionException if some other exception occurred during execution
@throws InterruptedException if the execution was interrupted
jib-core/src/main/java/com/google/cloud/tools/jib/api/JibContainerBuilder.java