Springboot app docker file

Use following docker file to build image with your Spring Boot application.

FROM java:8-jre-alpine
ARG JAR_FILE=target/demo-app-1.0.0.jar
ENV JAR_FILE=${JAR_FILE}
RUN mkdir app
COPY ${JAR_FILE} /app
WORKDIR /app
EXPOSE 8080
ENTRYPOINT  java -Dspring.profiles.active=production -jar ${JAR_FILE}

The Spring Boot application requires a java environment, so we select the base image java: 8-jre-alpine.

You can pass your jar file in JAR_FILE argument. By default, target/demo-app-1.0.0.jar will be used.

We create an app directory in the container and copy the jar file into it. And set this directory as the working directory.

Container will expose port 8080.

Finally, we set the container entry point, i.e. we specify the command to start the Spring Boot application.