Reputation: 7524
I have a very basic question about FROM line in dockerfile for a java application, like a spring boot app.
So we write it like:
FROM openjdk:11
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
In line 3 we are basically telling docker to use the application jar inside target folder for running the app inside container. Now when a jar is build for a java application, build process takes into account all the needed dependencies like those from jdk or those defined in POM etc.
So then why do we need FROM line? We already have all in our jar, isn't?
Upvotes: 0
Views: 76
Reputation: 2556
The FROM argument describes a base image to use. https://docs.docker.com/engine/reference/builder/#from
An analogy in a non containerized world would be sitting down to a computer freshly installed with some OS and various dependencies already setup for you. Handy!
In this specific case, you are getting an image from OpenJDK. https://hub.docker.com/_/openjdk.
Edit to add detail: As a number of comments state, Java needs the JVM installed on some OS to run a Java program. If you look down at image variants in the docker hub link, you'll see that you are requesting an image with Debian Linux and OpenJDK 11.
Upvotes: 1