@Test
  public void testOffline()
      throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException,
          RegistryException, CacheDirectoryCreationException {
    Path cacheDirectory = temporaryFolder.getRoot().toPath();

    JibContainerBuilder jibContainerBuilder =
        Jib.from(dockerHost + ":5000/busybox").setEntrypoint("echo", "Hello World");

    // Should fail since Jib can't build to registry offline
    try {
      jibContainerBuilder.containerize(
          Containerizer.to(RegistryImage.named("ignored")).setOfflineMode(true));
      Assert.fail();
    } catch (IllegalStateException ex) {
      Assert.assertEquals("Cannot build to a container registry in offline mode", ex.getMessage());
    }

    // Should fail since Jib hasn't cached the base image yet
    try {
      jibContainerBuilder.containerize(
          Containerizer.to(DockerDaemonImage.named("ignored"))
              .setBaseImageLayersCache(cacheDirectory)
              .setOfflineMode(true));
      Assert.fail();
    } catch (ExecutionException ex) {
      Assert.assertEquals(
          "Cannot run Jib in offline mode; "
              + dockerHost
              + ":5000/busybox not found in local Jib cache",
          ex.getCause().getMessage());
    }

    // Run online to cache the base image
    jibContainerBuilder.containerize(
        Containerizer.to(DockerDaemonImage.named("ignored"))
            .setBaseImageLayersCache(cacheDirectory)
            .setAllowInsecureRegistries(true));

    // Run again in offline mode, should succeed this time
    jibContainerBuilder.containerize(
        Containerizer.to(DockerDaemonImage.named(dockerHost + ":5000/offline"))
            .setBaseImageLayersCache(cacheDirectory)
            .setOfflineMode(true));

    // Verify output
    Assert.assertEquals(
        "Hello World\n", new Command("docker", "run", "--rm", dockerHost + ":5000/offline").run());
  }
Pulls a built image and attempts to run it.

@param imageReference the image reference of the built image
@return the container output
@throws IOException if an I/O exception occurs
@throws InterruptedException if the process was interrupted
jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java