Fix Version/s: tbd
Compatibility Risk Description:Minimal risk, because it's a new option, it won't affect existing ones.
Interface Kind:Java API, add/remove/modify command line option
Add a new mode to Java Packager that will generate a Docker container with a base OS image, a JDK, and optionally, a bundled application. This feature is intended to be easy to use: the user specifies a jar file or module as an input, and receives a Docker container as an output.
Due to increasing popularity of Docker containers, we propose to add a new mode to Java Packager for creating those containers. Java Packager will let us provide a nice level of control using JLink and JDeps to include only the necessary modules from the JDK, and potentially the application code. The Dockerfile created by Java Packager can be used to customize the Docker base image and other aspects of the container.
The Java Packager will perform the following four steps to generate a Docker container from a user application and JDK:
- Prepare parameters for JLink. For modular applications, this is done by using the dependencies in the module-info.java file of the application. For non-modular applications in a .jar file we need to calculate the dependencies using JDeps.
- Generate a custom runtime image using JLink and the specified parameters.
- Create a Dockerfile that contains instructions for copying the generated Java runtime image, application files (optional), and other necessary actions in order to configure the base image.
- Generate a Docker container using the created Dockerfile, auto-downloaded Linux base image, and other required files.
New arguments for generating Docker containers:
New mode for generating Docker containers.
Parameter for specifying Docker base image. Value is one of the following list: "ubuntu", "fedora", "debian", "centos", "oraclelinux". If not specified, we can consider using "ubuntu" by default.
Parameter for specifying JDK home in case javapackager is run on Windows or Mac OS. We might consider naming this "-target-jdk-home" or just "-jdk-home". If not specified, we can auto-download the latest Linux JDK from web, generate the app image, and remove downloaded JDK from the container.
Parameter for specifying the Dockerfile in case the user needs to perform additional configuration for the base image. If this option is used, we will only add the entrypoint to the provided Dockerfile.
Additionally, the user will be able to specify existing javapackager arguments, such as name, description, copyright, JVM args, etc.
JDK for generating custom runtime image
If user operates a Linux system, we can just use the current JDK, although -container-jdk-home will take precedence if specified. On non-Linux systems, we will use the JDK specified in "-container-jdk-home" and generate an interim Docker image for creating the final runtime image, or we will auto-download latest linux JDK from web if "-container-jdk-home" is not specified.
Docker container without user application files
If adding a user application is not required, the user will need to specify appropriate parameters for the existing options: "add-modules" (list of modules to add to jimage creation) and "strip-native-commands" (removes native executables from the jimage creation) to configure the Docker container appropriately.