Skip to main content

REST API Container

Examples on setting up REST API containers.

Spring Boot with Docker tutorial

References

Setup Notes

  • I followed the Build with Maven steps in this guide. One step the guide didn’t touch on was that the Maven Wrapper needed to be included. The guide had used the Spring Initializr to set up a base project and it includes the Maven Wrapper by default. To manually add the Maven Wrapper to a project created from scratch is to follow the steps outlined in https://www.baeldung.com/maven-wrapper. I added the wrapper with a specific Maven version of 3.6.3 since that’s the version of Maven I had installed globally (any version can be used within an individual project if you decide to use a specific version).

Basic Dockerfile

This Dockerfile was used with assumptions based on setup of Spring Initializr project that built the application JAR in a ‘target’ directory. The Dockerfile targets the source JAR as ‘target/*.jar’ and then copies it as ‘app.jar’, which is used as the launching entrypoint when the Dockerfile launches the app using the java command.

This is a basic setup and doesn’t not have hot reload setup. Any change to the application’s source must be recompiled to a JAR and the docker build and run commands must be re-run.

FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]