Sitemap

Docker Image :JAVA

1 min readOct 10, 2023

--

Below are the steps for docker image creation and writing docker file for a java program:

Docker File is written as:

FROM openjdk:11

COPY target/File_Name.jar app.jar

ENTRYPOINT [“java”,”-jar”,”/app.jar”]

  • Here openjdk:11 is the version of jdk which you are using
  • We create a new layer by copying the generated jar, File_Name.jar, from the target folder of the build context into the root folder of our container with the name app.jar.
  • We tell the container to run the app.jar using the java -jar command

Building a docker image :

Get Kumar Shubham’s stories in your inbox

Join Medium for free to get updates from this writer.

docker image build -t Jar_Name:Tag_Name .

  • -t is used to specify the name and the tag respectively
  • . is used to specify the current directory or we can also provide the directory from which we want to create a docker image instead of .
  • Jar_Name is our image name and Tag_Name is the tag name which we provided

docker run Jar_Name:Tag_Name

  • This runs our docker image provided that we are providing correct jar name and tag name

--

--