Java Magazine, May/June 2019
ORACLE COM JAVAMAGAZINE MAY JUNE 2019 27 containers Main java public class Main public static void main String args System out println Hello world It is hard to argue that Docker is not the most popular container distribution channel nowadays To distribute this Hello World application it would be a huge benefit to use Docker Because my intention is to both create a single Dockerfile and keep the final image as small as possible a multistage build is needed As a reminder a multistage Docker build allows you to chain stages in such a way that a later stage can reuse build results from previous stages In addition each stage can inherit from diferent base images and you can name each stage because it is easier to reference a stage by name than by index The main benefit of multistage builds is the ability to use the most relevant image in each stage so you can have the smallest resulting image at the end of the build process Heres an example Dockerfile showing how to create an image for Hello World by using Maven I assume the project has a Maven compatible structure Dockerfile FROM maven 36 jdk 12 alpine as build WORKDIR app COPY pom xml COPY src src RUN mvn package
You must have JavaScript enabled to view digital editions.