-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Frequently Asked Questions (FAQ)
If a question you have is not answered below, please submit an issue.
But, I'm not a Java developer.
What image format does Jib use?
Can I define a custom entrypoint?
But I just want to set some JVM flags when running the image?
Where is the application in the container filesystem?
I need to RUN commands like apt-get.
Can I ADD a custom directory to the image?
Can I build to a local Docker daemon?
I am seeing ImagePullBackoff on my pods.
I would like to run my application with a javaagent.
How can I tag my image with a timestamp?
See rules_docker for a similar existing container image build tool for the Bazel build system. The tool can build images for languages such as Python, NodeJS, Java, Scala, Groovy, C, Go, Rust, and D.
Jib currently builds into the Docker V2.2 image format or OCI image format.
See Extended Usage for the imageFormat configuration.
See Extended Usage for the format configuration.
The plugin attaches a default entrypoint that will run your application automatically.
When running the image, you can override this default entrypoint with your own custom command.
See docker run --entrypoint reference for running the image with Docker and overriding the entrypoint command.
See Define a Command and Arguments for a Container for running the image in a Kubernetes Pod and overriding the entrypoint command.
When running the image, you can pass in additional JVM flags via the JAVA_TOOL_OPTIONS environment variable.
See docker run -e reference for running the image with Docker and setting environment variables.
See Define Environment Variables for a Container for running the image in a Kubernetes Pod and setting environment variables.
Jib packages your Java application into the following paths on the image:
-
/app/libs/contains all the dependency artifacts -
/app/resources/contains all the resource files -
/app/classes/contains all the classes files
Running commands like apt-get slows down the container build process. We do not recommend or support running commands as part of the build.
However, if you need to run commands, you can build a custom image and configure Jib to use it as the base image.
Base image configuration examples
In jib-maven-plugin, you can then use this custom base image by adding the following configuration:
<configuration>
<from>custom-base-image</from>
</configuration>In jib-gradle-plugin, you can then use this custom base image by adding the following configuration:
jib.from.image = 'custom-base-image'We currently do not support adding a custom directory to the image. If your application needs to use custom files, place them into your application's resources directory (src/main/resources by default). These resource files will be available on the classpath.
We currently do not support building to a local Docker daemon. However, this feature is in the pipeline and will be added in the future.
You can still docker pull the image built with jib-maven-plugin to have it available in your local Docker daemon.
You can also run a local Docker registry and point Jib to push to the local registry.
I am seeing ImagePullBackoff on my pods (in minikube).
When you use your private image built with Jib in a Kubernetes cluster, the cluster needs to be configured with credentials to pull the image. This involves 1) creating a Secret, and 2) using the Secret as imagePullSecrets.
kubectl create secret docker-registry registry-json-key \
--docker-server=<registry> \
--docker-username=<username> \
--docker-password=<password> \
--docker-email=<any valid email address>
kubectl patch serviceaccount default \
-p '{"imagePullSecrets":[{"name":"registry-json-key"}]}'For example, if you are using GCR, the commands would look like (see Advanced Authentication Methods):
kubectl create secret docker-registry gcr-json-key \
--docker-server=https://gcr.io \
--docker-username=_json_key \
--docker-password="$(cat keyfile.json)" \
--docker-email=any@valid.com
kubectl patch serviceaccount default \
-p '{"imagePullSecrets":[{"name":"gcr-json-key"}]}'See more at Using Google Container Registry (GCR) with Minikube.
TODO: Provide solution.
TODO: Provide solution.
To tag the image with a simple timestamp, add the following to your pom.xml:
<properties>
<maven.build.timestamp.format>yyyyMMdd-HHmmssSSS</maven.build.timestamp.format>
</properties>Then in the jib-maven-plugin configuration, set the tag to:
<configuration>
<tag>${maven.build.timestamp}</tag>
</configuration>You can then use the same timestamp to reference the image in other plugins.
To tag the image with a timestamp, simply set the timestamp as the tag for to.image in your jib configuration. For example:
jib.to.image = 'gcr.io/my-gcp-project/my-app:' + System.nanoTime()