Creating Docker images for Grails applications with Jib

Jib is a Java-native container builder that turns an application into an OCI image without requiring a Docker daemon. For Grails developers, that removes a familiar source of friction: the Gradle build can compile the app, assemble the runtime and publish the image while Groovy-based project configuration remains the source of truth.

Unlike a hand-written Dockerfile, the build tool decides how to divide application files, dependencies and JVM layers. Jib can reuse unchanged layers, reproduce the same inputs more reliably and push directly to a registry. That makes container creation fit naturally into a continuous integration pipeline instead of turning a developer’s laptop into a miniature production environment.

The workflow below uses a standard Grails WAR, a Java 17 base image and Jib’s Gradle plugin. It also covers packaging, registry access, runtime configuration and the regional, privacy and scheduling details that matter to teams building from Australia.

Why Jib suits a Grails workflow

Start by separating compilation from image transport. A normal Grails build still produces a testable application and deployable WAR; Jib adds an image-building phase after those artifacts are ready. There is no need to rewrite the project as a Spring Boot service or maintain two build definitions. The plugin can take the existing Gradle output and create a portable image that runs on a laptop, an Elastic Container Service task or a Kubernetes cluster.

Layer reuse is particularly valuable for Groovy applications. Source files, dependency jars and resources can remain stable while a small changed layer carries the new release. Jib also records the entrypoint and exposed port in the image configuration, which gives orchestrators a consistent contract. Because the builder understands Java artifacts, it avoids the broad copy-everything pattern that produces slow builds and oversized images.

An application is rarely isolated, however. A Grails service that publishes order events or chat messages may also depend on RabbitMQ. The RabbitMQ backend guide shows a practical event-driven backend, while the container here remains focused on packaging the Grails tier; queues, databases and monitoring still need their own operational plans.

Configure Jib in a Grails Gradle build

Add the plugin beside the existing Grails plugins. Pin an approved Jib release rather than relying on a dynamic version, because image output should change only when the team intends to review it.

plugins {
    id "org.grails.grails-web"
    id "war"
    id "com.google.cloud.tools.jib" version "3.4.5"
}

Most generated Grails applications already include org.grails.grails-web and the war plugin. Keep those declarations and add com.google.cloud.tools.jib; the exact release shown here is a working baseline, while the project should move to a currently supported patch after checking its compatibility notes. In a larger team, a Gradle version catalog or shared convention plugin can keep the Jib version consistent across services.

Place the Jib extension in build.gradle, not in an application class, and keep environment-specific values outside source control. The following sections configure the extension gradually so each part remains easy to test: plugin first, application packaging next, then registry and runtime details.

Package the application for a container

A Grails WAR can contain an executable Spring Boot archive, but the container must receive both the archive and a correct startup command. Jib does not infer every Grails deployment convention, so the build should copy the WAR to a staging directory and expose it at a known path. Test the archive with java -jar during development; a WAR meant only for an external servlet container requires a different command.

The following configuration prepares the WAR, selects a JRE base image, publishes to a named registry and sets the container entrypoint. The extra directory becomes part of the image, so /app.war is present when the container starts.

def jibExtraDir = layout.buildDirectory.dir("jib-extra").get().asFile
def registryUsername = System.getenv("REGISTRY_USERNAME")
def registryPassword = System.getenv("REGISTRY_PASSWORD")

tasks.register("prepareJibWar", Copy) {
    from tasks.named("war")
    into jibExtraDir
}

jib {
    dependsOn("prepareJibWar")

    from {
        image = "eclipse-temurin:17-jre"
    }

    to {
        tags = ["grails-app:${project.version}".toString()]
        repositories = [System.getenv("CONTAINER_REGISTRY") ?: "registry.example.com"]

        if (registryUsername && registryPassword) {
            credentials {
                username = registryUsername
                password = registryPassword
            }
        }
    }

    container {
        entrypoint = ["java", "-jar", "/app.war"]
        ports = [8080]
    }

    extraDirectories = [jibExtraDir]
}

Using Java 17 is a sensible baseline for Grails versions that support it; match the major release to the framework and upgrade the base image with the application. The WAR filename can vary by version, which is why copying the task output is safer than hard-coding build/libs/application.war. For a smaller image, a project-native boot JAR may be preferable, but it should be tested with Grails plugins and static resources.

Build, authenticate and push safely

Set the registry and credentials in the shell or, preferably, in the CI secret store. Do not commit them to build.gradle, a Gradle properties file checked into source control or a shell script. On a developer machine, a short-lived environment variable reduces accidental reuse; in CI, prefer an identity role or short-lived token with permission to push only this repository.

export CONTAINER_REGISTRY=registry.example.com
export REGISTRY_USERNAME=your-account
export REGISTRY_PASSWORD='use-a-short-lived-secret'
./gradlew jib

The jib task builds and pushes directly to the configured registry. Use jibDockerBuild only when a local daemon and a Docker-format image are genuinely required, or jibBuildTar for a portable archive. Cached layers make later builds quick, but an intentional base-image refresh should use controlled cache invalidation or a fresh CI worker rather than an unnoticed old JRE.

Tags are convenient labels, not immutable releases. A content-heavy service such as the 188ESport website still benefits from versioned publishing, verification and rollback because pages, data feeds and promotions can change together. Tag each Grails release with a unique version, record the resulting digest in deployment evidence and promote that digest between environments. This prevents a moving tag from turning two supposedly identical deployments into different runtime artifacts.

Tune the runtime for production

Treat the image as the runtime contract, not simply a package for the WAR. Expose port 8080 for HTTP, keep non-sensitive settings in environment variables and configure the image to run as a non-root user where the Grails build permits it. On an Apple Silicon laptop, select the target architecture to match the deployment platform rather than assuming local arm64 is also the server architecture. Secrets must never be copied into image layers, because anyone who can pull the image may be able to recover them.

Java’s container awareness should guide memory settings. JAVA_TOOL_OPTIONS=-XX:MaxRAMPercentage=75.0 lets the JVM use the container limit while leaving room for the operating system, threads and native memory. Confirm the value against the workload, and change it through the deployment environment rather than rebuilding the image. Connection pools, heap size and request concurrency often need separate tuning.

Use orchestrator readiness and liveness probes against an appropriate Grails endpoint, restrict that endpoint if it reveals internals, and give the JVM enough time to shut down when a container receives SIGTERM. Externalise logs with clear retention controls, and record the image digest, configuration revision and deployment time. These checks catch the early failures that a successful Gradle build cannot.

Use Australian cloud and privacy patterns

Australian teams have several sensible regional choices. AWS Elastic Container Registry in Sydney uses the ap-southeast-2 region, while Azure Container Registry can sit in Australia East; Melbourne and Sydney are major centres for software hiring, and Brisbane and Perth organisations also need a policy explaining where application data and logs reside. The local market includes hyperscale clouds, local hosting providers and managed platforms, so the registry decision should follow workload ownership rather than habit.

Time zones deserve explicit attention. Sydney, Melbourne and Adelaide change their UTC offset at the start and end of daylight saving, while Perth remains on Western Standard Time. A pipeline that schedules tests, image builds or production changes in UTC will therefore move relative to the local workday twice a year. Teams should publish deployment windows in the office timezone, retain UTC timestamps in audit logs and avoid signing off a release while an automatic cutover is running unattended.

If the service handles personal information, Australian privacy obligations belong in the container design. For covered organisations and their service providers, the Privacy Act 1988 and Australian Privacy Principles influence what is collected, retained and disclosed. The Notifiable Data Breaches scheme can require assessment and notification when eligible information is compromised. A minimised image, encrypted transport, restricted logs and secret injection reduce exposure, but they do not replace a documented privacy and incident-response process.

Make container delivery repeatable

Put the build in CI and make the registry the handoff between testing and deployment. A practical pipeline checks out the Grails project, installs the required Java version, restores Gradle caches, runs tests, executes jib, scans the digest and records provenance. AWS IAM roles, OIDC federation or the CI platform’s secret store can remove long-lived cloud keys. Deployment then references the digest produced by that run rather than rebuilding locally.

Make the release rhythm visible to the people on call. A common Australian development-day routine is a brief stand-up after the morning coffee, followed by a go/no-go check on the build, the expected smoke test and the rollback trigger. Whether the team is in Brisbane, Melbourne or Perth, that short shared routine helps prevent an image from reaching production while its health check is still failing.

Begin with one Grails service and one repository, then apply the same naming, tagging and evidence rules to the rest of the portfolio. For a tailored walkthrough using your Gradle layout and cloud registry, contact Grails Example with the Grails version, Java version and deployment target.