Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FAQ for Jib CLI #3118

Merged
merged 11 commits into from
Mar 17, 2021
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ If a question you have is not answered below, please [submit an issue](/../../is
| What do you like best about Jib? What needs to be improved? Please tell us by taking a [one-minute survey](https://forms.gle/YRFeamGj51xmgnx28). Your responses will help us understand Jib usage and allow us to serve our customers (you!) better. |

[But, I'm not a Java developer.](#but-im-not-a-java-developer)\
[My build process doesn't let me integrate with the Jib plugins](#my-build-process-doesnt-let-me-integrate-with-the-jib-plugins)\
[How do I run the image I built?](#how-do-i-run-the-image-i-built)\
[Where is bash?](#where-is-bash)\
[What image format does Jib use?](#what-image-format-does-jib-use)\
Expand Down Expand Up @@ -47,6 +48,10 @@ If a question you have is not answered below, please [submit an issue](/../../is
[I am seeing `Method Not Found` or `Class Not Found` errors when building.](#i-am-seeing-method-not-found-or-class-not-found-errors-when-building)\
[Why won't my container start?](#why-wont-my-container-start)

**Jib CLI**\
[How does the `jar` command support Standard JARs?](#how-does-the-jar-command-support-standard-jars)\
[How does the `jar` command support Spring Boot JARs?](#how-does-the-jar-command-support-spring-boot-jars)

---

### But, I'm not a Java developer.
Expand All @@ -55,6 +60,16 @@ Check out [Jib CLI](https://github.com/GoogleContainerTools/jib/tree/master/jib-

Also see [rules_docker](https://github.com/bazelbuild/rules_docker) for a similar existing container image build tool for the [Bazel build system](https://github.com/bazelbuild/bazel). The tool can build images for languages such as Python, NodeJS, Java, Scala, Groovy, C, Go, Rust, and D.

### My build process doesn't let me integrate with the Jib plugins
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved

The [Jib CLI](https://github.com/GoogleContainerTools/jib/tree/master/jib-cli) can be useful for users with complex build workflows that make it hard to integrate the Jib Maven or Gradle plugins. It is a standalone application that is powered by [Jib-Core](#https://github.com/GoogleContainerTools/jib/tree/master/jib-core) and offers two commands:
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved

[Build](https://github.com/GoogleContainerTools/jib/tree/master/jib-cli#build-command): Which builds from the file system content with the help of a yaml build file.
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved

[Jar](https://github.com/GoogleContainerTools/jib/tree/master/jib-cli#jar-command): Which opens up your JAR into optimized layers on the container or containerizes it as-is. It will also intelligently determine the entrypoint of the container, based on how the JAR is containerized.

Check out the [Jib CLI section](#jib-cli) of the FAQ for more information.

### How do I run the image I built?

If you built your image directly to the Docker daemon using `jib:dockerBuild` (Maven) or `jibDockerBuild` (Gradle), you simply need to use `docker run <image name>`.
Expand Down Expand Up @@ -756,3 +771,48 @@ On examining the container structure with [Dive](https://github.com/wagoodman/di
The user had used Jib's ability to install extra files into the image ([Maven](https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#adding-arbitrary-files-to-the-image), [Gradle](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin#adding-arbitrary-files-to-the-image)) to install a library file by placing it in `src/main/jib/lib/libfoo.so`. This would normally cause the `libfoo.so` to be installed in the image as `/lib/libfoo.so`. But `/lib` and `/lib64` in the user's base image were symbolic links. Jib does not follow such symbolic links when creating the image. And at container initialization time, Docker treats these symlinks as a file, and thus the symbolic link was replaced with `/lib` as a new directory. As a result, none of the system shared libraries were resolved and dynamically-linked programs failed.

Solution: The user installed the file in a different location.

## Jib CLI

### How does the `jar` command support Standard JARs?
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved

A standard JAR can be containerized by the `jar` command in two modes, exploded or packaged.

#### Exploded Mode (Recommended)
Achieved by calling `jib jar --target ${TARGET_REGISTRY} ${JAR_NAME}.jar`
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
It is the default mode for containerizing a JAR. It will open up the JAR into the following layers:
- Dependencies Layer: Contains dependencies whose versions do not contain `SNAPSHOT`. Note that this layer will not be created if `Class-Path` is not present in the manifest.
- Snapshot-Dependencies Layer: Contains dependencies whose versions contain `SNAPSHOT`. Note that this layer will not be created if `Class-Path` is not present in the manifest.
- Resources Layer: Contains resources parsed from the JAR. Note that it will also include `MANIFEST.MF`.
- Classes Layer: Contains classes parsed from the JAR.

**Entrypoint** : `java -cp /app/dependencies/:/app/explodedJar/ ${MAIN_CLASS}`

#### Packaged Mode
Achieved by calling `jib jar --target ${TARGET_REGISTRY} ${JAR_NAME}.jar --mode packaged`.
It will result in the following layers on the container:
- Dependencies Layer: Contains the dependencies derived from `Class-Path` in the JAR's manifest. Note that this layer will not be created if `Class-Path` is not present in the manifest.
- Jar Layer: Contains the original JAR.

**Entrypoint** : `java -jar ${JAR_NAME}.jar`

### How does the `jar` command support Spring Boot JARs?
The `jar` command currently supports containerization of Spring Boot Fat JARs.
A Spring-Boot Fat JAR can be containerized in two modes, exploded or packaged.
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved

#### Exploded Mode (Recommended)
Achieved by calling `jib jar --target ${TARGET_REGISTRY} ${JAR_NAME}.jar`
It is the default mode for containerizing a JAR. It will create layers according to what is specified in the `layers.idx` file of the jar, if present, or according to following format:
- Dependencies Layer: For a dependency whose version does not contain `SNAPSHOT`.
- Spring-Boot-Loader Layer: Contains JAR loader classes.
- Snapshot-Dependencies Layer: For a dependency whose version contains `SNAPSHOT`.
- Resources Layer: Contains resources parsed from `BOOT-INF/classes/` in the JAR and `META-INF/`.
- Classes Layer: Contains classes parsed from `BOOT-INF/classes/` in the JAR.

**Entrypoint** : `java -cp /app org.springframework.boot.loader.JarLauncher`

#### Packaged Mode
Achieved by calling `jib jar --target ${TARGET_REGISTRY} ${JAR_NAME}.jar --mode packaged`
It will containerize the JAR as is. However, **note** that we highly recommend against using packaged mode for containerizing Spring Boot fat JARs.

**Entrypoint**: `java -jar ${JAR_NAME}.jar`