Jib custom entrypoint

  docker

Order

This article focuses on the use of jib’s custom entrypoint.

maven

            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>0.9.10</version>
                <configuration>
                    <container>
                        <ports>
                            <port>8080</port>
                        </ports>
                        <useCurrentTimestamp>true</useCurrentTimestamp>
                        <entrypoint>
                            <arg>/bin/sh</arg>
                            <arg>-c</arg>
                            <arg>java ${JAVA_OPTS} -cp /app/resources/:/app/classes/:/app/libs/* com.example.JibDemoApplication</arg>
                        </entrypoint>
                    </container>
                    <from>
                        <image>java:8u172-jre-alpine</image>
                    </from>
                    <to>
                        <image>jib-demo:${maven.build.timestamp}</image>
                    </to>
                    <allowInsecureRegistries>true</allowInsecureRegistries>
                    <extraDirectory>${project.basedir}/src/main/jib</extraDirectory>
                </configuration>
            </plugin>
  • Entrypoint is customized under the container tag, and then environment variables are injected, so that the jvm configuration does not have to be written to the pom file.
  • Originally, the entrypoint generated by default by jib is in quotation mark mode, for example
"Entrypoint": [
                "java",
                "-Xms512m",
                "-cp",
                "/app/resources/:/app/classes/:/app/libs/*",
                "com.example.JibDemoApplication"
            ]

This mode does not seem to support environment variables, so it needs to be changed to a mode without quotation marks and started with sh -c java command

run

docker run -p 8080:8080 -e JAVA_OPTS='-Xms512m -Xmx512m' --rm jib-demo:20180903

In this way, the JVM can be successfully configured using JAVA_OPTS environment variables.

Summary

Jib’s custom entrypoint is only supported in version 0.9.10 and above. if you need to customize entrypoint, please upgrade the jib version first.

doc