Gradle is a build tool with a focus on build automation and support for multi-language development.
Pull the latest version of this image from the Ghost registry. Pulling requires authentication — generate a token and run docker login first (see Authentication below).
The Ghost catalog is public to browse, but pulling images requires an account. Generate a pull token below (or from your Account → Tokens page) — you'll get a ready-to-paste docker login command, then docker pull works.
The username is generated automatically (it looks like robot$<project>+<auto-id>, not the name you typed) and is included in the docker login command above. The secret is shown only once when you create the token.
All Ghost images are signed with cosign. Verifying the signature before deployment ensures the image has not been tampered with.
Install cosign via brew install cosign or download from the Sigstore releases page.
Reference this image in your Dockerfile as a base layer:
All examples in this guide use the public image. If you’ve mirrored the repository for your own use (for example, to your Docker Hub namespace), update your commands to reference the mirrored image instead of the public one.
For example:
registry.ghost-prod.alphabravo.io/ghost-base/<repository>:<tag><your-namespace>/dhi-<repository>:<tag>For the examples, you must first use docker login registry.ghost-prod.alphabravo.io to authenticate to the registry to pull the images.
Run this from the directory of the Gradle project you want to build. Replace <gradle-task> with the Gradle task you
want to run.
$ docker run --rm -v "$(pwd)":/build registry.ghost-prod.alphabravo.io/ghost-base/gradle:<tag> <gradle-task>
To explore the following examples, you can use your own app, or create a sample Gradle project using the Docker Hardened Gradle image. This approach uses bind mounts and is compatible with all the use cases in this guide.
First, create an empty directory for the project:
$ mkdir gradle-demo && cd gradle-demo
Then, initialize a new Gradle application project using the Docker image:
$ docker run --rm -v "$(pwd)":/build registry.ghost-prod.alphabravo.io/ghost-base/gradle:<tag> \
init --type java-application --dsl kotlin --test-framework junit \
--project-name gradle-demo --package org.example
You now have a complete Gradle project to use with the examples in this guide.
You can build a local project by bind mounting your project directory into the container and running the build task.
$ docker run --rm \
-v "$(pwd)":/build \
registry.ghost-prod.alphabravo.io/ghost-base/gradle:<tag> \
build
You can create executable JAR files by running the assemble task. This task compiles your code and packages it into
JAR or WAR files, depending on your project configuration.
$ docker run --rm \
-v "$(pwd)":/build \
registry.ghost-prod.alphabravo.io/ghost-base/gradle:<tag> \
clean assemble
Ghost hardened images for Gradle are build-only tools. They contain no runtime variants because Gradle builds applications but doesn't run them. You must use multi-stage Dockerfiles to copy build artifacts to appropriate runtime images.
The following example uses the Ghost hardened image for Eclipse Temurin as the runtime stage.
# syntax=docker/dockerfile:1
# Build stage - Gradle DHI for building
FROM registry.ghost-prod.alphabravo.io/ghost-base/gradle:<tag> AS build
# Copy Gradle files for better caching (working directory is /build by default)
COPY settings.gradle.kts ./
COPY app/build.gradle.kts app/
COPY gradlew gradlew.bat ./
COPY gradle/ gradle/
COPY app/src app/src
# Build the application
RUN --mount=type=cache,target=/home/gradle/.gradle \
gradle clean assemble --no-daemon
# Runtime stage - JRE for running the application
FROM registry.ghost-prod.alphabravo.io/ghost-base/eclipse-temurin:<tag> AS runtime
WORKDIR /app
COPY --from=build /build/app/build/libs/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-cp", "app.jar", "org.example.App"]
The following table summarizes the key differences between standard Docker Gradle images and Docker hardened Gradle images.
| Feature | Docker Official Image | Ghost hardened image |
|---|---|---|
| Security | Standard base with common utilities | Custom hardened Debian/Alpine with security patches |
| Package manager | Full package managers (apt, apk) | Package managers only in Alpine variants |
| Attack surface | Large | Minimal |
| Utilities | Full dev toolchain | Minimal (Gradle, JDK, core tools only) |
| Debugging | Traditional shell debugging | Use Docker Debug or entrypoint override |
Ghost hardened images come in different variants depending on their intended use. The Gradle Ghost hardened images are
intended for build-time only. All variants include dev in the tag name and are designed for use in build stages of
multi-stage Dockerfiles.
Switching to the hardened Gradle image does not require any special changes. You can use it as a drop-in replacement for the standard Gradle image in your existing workflows and configurations. Note that the entry point for the hardened image may differ from a standard image, so ensure that your commands and arguments are compatible.
gradle:<tag>registry.ghost-prod.alphabravo.io/ghost-base/gradle:<tag>The following are common issues that you may encounter during migration.
The hardened images intended for runtime don't contain a shell nor any tools for debugging. The recommended method for debugging applications built with Ghost hardened images is to use Docker Debug to attach to these containers. Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.
By default image variants intended for runtime, run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user. You may need to copy files to different directories or change permissions so your application running as the nonroot user can access them.
Non-dev hardened images run as a nonroot user by default. As a result, applications in these images can't bind to privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10.
By default, image variants intended for runtime don't contain a shell. Use dev images in build stages to run shell
commands and then copy any necessary artifacts into the runtime stage. In addition, use Docker Debug to debug containers
with no shell.
Ghost hardened images may have different entry points than images such as Docker Official Images. Use docker inspect
to inspect entry points for Ghost hardened images and update your Dockerfile if necessary.