Docker KBean¶
Builds and runs image based on project.
This KBean can build JVM and Native (AOT) images from an existing project.
This KBean exposes the following fields:
Field | Description |
---|---|
jvmImageName [String] | Explicit full name of the JVM image to build. It may includes placeholders such as '$version', '$groupId', and '$artifactId'. If not specified, the image name will be inferred form the project information. |
nativeImageName [String] | Explicit full name of the native image to build. It may includes placeholders such as '$version', '$groupId', and '$artifactId'. If not specified, the image name will be inferred form the project information. |
jvmBaseImage [String] | Base image to construct the Docker image. |
jvmOptions [String] | Space-separated list of additional JVM options to use when running the container's Java process. |
nativeBaseImage [String] | Base image for the native Docker image to build. It can be replaced by a distro-less image as 'gcr.io/distroless/static-debian12:nonroot'. |
nativeNonRootUser [enum:JkDockerBuild$NonRootMode] | Specifies the policy for creating a non-root user in the native Docker image. |
jvmNonRootUser [enum:JkDockerBuild$NonRootMode] | Specifies the policy for creating a non-root user in the JVM Docker image. |
This KBean exposes the following methods:
Method | Description |
---|---|
build | Builds Docker image in local registry. |
buildNative | Builds native Docker image in local registry. |
info | Displays info about the Docker image. |
infoNative | Displays info about the native Docker image. |
DockerKBean
allows the creation of Docker images for both project and base KBeans. It supports generating JVM-based images as well as minimalist Docker images containing only the native executable.
Key Features:
- Efficiently create layered and secure Docker images for JVM applications
- Generate secure, optimized Docker images for native applications
- Infer image name/version from the project
- Optionally switch to a non-root user (configurable)
- Customize the generated image via Java API
Example Invocation:
- jeka docker:buildNative
: Builds a native Docker image of your application.
Example Configuration:
@docker.nativeBaseImage=gcr.io/distroless/static-debian12:nonroot
Example For Image customization:
@JkPostInit
private void postInit(DockerKBean dockerKBean) {
dockerKBean.customizeJvmImage(dockerBuild -> dockerBuild
.addAgent("io.opentelemetry.javaagent:opentelemetry-javaagent:1.32.0", "")
.setBaseImage("eclipse-temurin:21.0.1_12-jre-jammy")
.nonRootSteps // inserted after USER nonroot
.addCopy(Paths.get("jeka-output/release-note.md"), "/release.md")
.add("RUN chmod a+rw /release.md ")
);
}
It’s easy to see the customization result by executing jeka docker: info
.
This will display details about the built image, including the generated Dockerfile.
You can also visit the generated Docker build directory,
which contains all the Docker context needed to build the image with a Docker client.