Going to Production with Docker
Learn how to deploy our application using Dockerfile.
In this day and age, keeping our production machines updated with the latest version of Java can be a burden for the operations team. They already track OS patches and everything else.
By using Docker, we can bundle our application into a container with Java baked right in.
Deploying with Docker
Let’s create our Dockerfile
:
FROM adoptopenjdk/openjdk8:latestARG JAR_FILE=target/*.jarCOPY ${JAR_FILE} app.jarENTRYPOINT ["java","-jar","/app.jar"]
We can do really complex stuff when building a Docker container. This isn’t one. This is about as simple as we can make things.
-
In line 1, we base the container on a well-established OpenJDK provider.
-
In line 3, we pattern-match the generated JAR file.
-
In line 5,we copy the JAR file into the container under a generic name.
-
In line 7, we launch the container at the launch point to start the JAR file as if we were typing “java-jar” in the previous section. This is so simple and is a real testimony to the ease of Spring Boot’s über JAR support.
So what’s wrong?
Docker has a caching system built-in. It uses layering to reduce the time it takes to build a container. Many parts of a Dockerfile
can be captured into a layer so that only the ...