- add
<finalName>jar-filname</finalName>to pom.xml under<build></build>tag. - Create package aka build_jar of application using maven command. Which will build a jar with the given filename inside
target/. - pull a specific image from docker hub of cmd using
docker pull image_name:tag. Here I usedopenjdk:25-jdk. - create a container instance from the image using
docker run openjdk:25-jdkordocker exec openjdk:25-jdk - Now try running your java application using
java -jar target/jar-filname.jar. docker run -dit openjdk:25-jdkrun this image to create a container where-ditmeans detached interactive mode.docker exec container_name ls -arunning this will execute the created container and list all the folders inside it.- Now copy the jar file and place it inside the
/tmpfolder usingdocker cp target/jar-filname.jar container_name:/tmp. docker commit container_name image-name:versionwill create a new image of your application.- Now if you try executing the image it will still open the jshell because it is by default.
- To change that you need to execute
docker commit --change='CMD ["java", "-jar", "/tmp/jar-filname.jar"]' container_name image-name:version, which edits the default execution command in docker. - Since your application is containerized, you are all set to run this using
docker run -p 8082:8082 image-name:versionon the specified port.
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|