GoogleContainerTools/jib · error · IllegalStateException
Cannot build to a container registry in offline mode
Error message
Cannot build to a container registry in offline mode
What it means
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.
Source
Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/api/Containerizer.java:283
* @param allowInsecureRegistries if {@code true}, insecure connections will be allowed
* @return this
*/
public Containerizer setAllowInsecureRegistries(boolean allowInsecureRegistries) {
this.allowInsecureRegistries = allowInsecureRegistries;
return this;
}
/**
* Sets whether or not to run the build in offline mode. In offline mode, the base image is
* retrieved from the cache instead of pulled from a registry, and the build will fail if the base
* image is not in the cache or if the target is an image registry.
*
* @param offline if {@code true}, the build will run in offline mode
* @return this
*/
public Containerizer setOfflineMode(boolean offline) {
if (mustBeOnline && offline) {
throw new IllegalStateException("Cannot build to a container registry in offline mode");
}
this.offline = offline;
return this;
}
/**
* Sets the name of the tool that is using Jib Core. The tool name is sent as part of the {@code
* User-Agent} in registry requests and set as the {@code created_by} in the container layer
* history. Defaults to {@code jib-core}.
*
* @param toolName the name of the tool using this library
* @return this
*/
public Containerizer setToolName(String toolName) {
this.toolName = toolName;
return this;
}
View on GitHub (pinned to fb949e2676)
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
Example fix
// before
Containerizer.to(RegistryImage.named("repo/img")).setOfflineMode(true);
// after
Containerizer.to(DockerDaemonImage.named("repo/img")).setOfflineMode(true); Defensive patterns
Strategy: type-guard
Validate before calling
if (target instanceof RegistryImage && offline) throw new IllegalStateException("Registry target cannot be offline"); Type guard
boolean offlineAllowed(Containerizer c) { return !isRegistryTarget(c); } Try / catch
try { containerizer.setOfflineMode(offline); } catch (IllegalStateException e) { containerizer = rebuildForDaemonTarget(); containerizer.setOfflineMode(offline); } Prevention
- 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
When it happens
Trigger: Calling containerizer.setOfflineMode(true) after Containerizer.to(RegistryImage.named(...)); mustBeOnline is true for registry targets, so the combination is rejected at configuration time.
Common situations: 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.
Related errors
- Image name must be set when building a TarImage; use TarImag
- Invalid container configuration in Docker V2.2/OCI manifest:
- <message from BuildStepsExecutionException>
- <message from BuildStepsExecutionException>
- Path does not start with forward slash (/): ${unixPath}
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/be2756b4ce1a307f.
Report an issue: GitHub.