{"record":{"id":"be2756b4ce1a307f","repo":"GoogleContainerTools/jib","slug":"cannot-build-to-a-container-registry-in-offline-mo","errorCode":null,"errorMessage":"Cannot build to a container registry in offline mode","messagePattern":"Cannot build to a container registry in offline mode","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/api/Containerizer.java","lineNumber":283,"sourceCode":"   * @param allowInsecureRegistries if {@code true}, insecure connections will be allowed\n   * @return this\n   */\n  public Containerizer setAllowInsecureRegistries(boolean allowInsecureRegistries) {\n    this.allowInsecureRegistries = allowInsecureRegistries;\n    return this;\n  }\n\n  /**\n   * Sets whether or not to run the build in offline mode. In offline mode, the base image is\n   * retrieved from the cache instead of pulled from a registry, and the build will fail if the base\n   * image is not in the cache or if the target is an image registry.\n   *\n   * @param offline if {@code true}, the build will run in offline mode\n   * @return this\n   */\n  public Containerizer setOfflineMode(boolean offline) {\n    if (mustBeOnline && offline) {\n      throw new IllegalStateException(\"Cannot build to a container registry in offline mode\");\n    }\n    this.offline = offline;\n    return this;\n  }\n\n  /**\n   * Sets the name of the tool that is using Jib Core. The tool name is sent as part of the {@code\n   * User-Agent} in registry requests and set as the {@code created_by} in the container layer\n   * history. Defaults to {@code jib-core}.\n   *\n   * @param toolName the name of the tool using this library\n   * @return this\n   */\n  public Containerizer setToolName(String toolName) {\n    this.toolName = toolName;\n    return this;\n  }\n","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/api/Containerizer.java#L265-L301","documentation":"Offline mode disables all network access for base image and dependency pulls. Registry-target builds inherently require network access, so calling setOfflineMode(true) on a Containerizer configured for a registry target (mustBeOnline set via to(RegistryImage...)) throws IllegalStateException immediately.","triggerScenarios":"Calling containerizer.setOfflineMode(true) after Containerizer.to(RegistryImage.named(...)); mustBeOnline is true for registry targets, so the combination is rejected at configuration time.","commonSituations":"Reusing a shared containerizer-building method for both registry and daemon/tar targets and enabling offline for local builds; CI environments without network trying to push to a registry.","solutions":["Remove setOfflineMode(true) when the target is a registry, or build to a Docker daemon (DockerDaemonImage) or tar (TarImage) target in offline mode","Make sure base image and dependencies are available locally and switch target to DockerDaemonImage before enabling offline","Gate offline mode on the target type in shared configuration code"],"exampleFix":"// before\nContainerizer.to(RegistryImage.named(\"repo/img\")).setOfflineMode(true);\n// after\nContainerizer.to(DockerDaemonImage.named(\"repo/img\")).setOfflineMode(true);","handlingStrategy":"type-guard","validationCode":"if (target instanceof RegistryImage && offline) throw new IllegalStateException(\"Registry target cannot be offline\");","typeGuard":"boolean offlineAllowed(Containerizer c) { return !isRegistryTarget(c); }","tryCatchPattern":"try { containerizer.setOfflineMode(offline); } catch (IllegalStateException e) { containerizer = rebuildForDaemonTarget(); containerizer.setOfflineMode(offline); }","preventionTips":["Tie offline mode to daemon/tar targets only in shared build code","Document that registry pushes always require network","Parameterize target type and offline flag together"],"tags":["jib","offline-mode","registry","containerizer"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}