Site icon NgDeveloper

Spring Boot Docker Deployment Steps

Spring Boot Docker Deployment Steps

Pre requisite:

[code]
sudo yum install java-1.8.0
sudo yum remove java-1.7.0-openjdk

[/code]

[code]
sdk install maven

[/code]

Note: SDKMan can be used to install the maven.

Spring Boot Jar – Docker Deployment Steps:

Step 1: Create some folder in your linux machine.[create build folder inside /var]

Step 2: Docker deployment file creation

Create the below content as Dockerfile: [Filename: Dockerfile without any extension and must be available in “/var/build” path]

[code]

FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY yourjarname-1.0 yourjarname.jar
ENTRYPOINT [“java”,”-Djava.security.egd=file:/dev/./urandom”,”-jar”,”/yourjarname.jar”]

[/code]

Here yourjarname-1.0 is assumed like the original file name which is created from spring boot and yourjarname.jar is the one you would like to rename it.

Step 3: Put the above created docker file and your spring boot jar in same folder. [/var/build]

Now Dockerfile and yourjarname.jar file available in /var/build path.

 

Step 4: Remove the existing container if any

Not needed if you are doing first time, needed if you want to deploy from second time.

[code]
sudo docker rm -f yourdockercontainername || true

[/code]

 

Step 5: Docker build command

[code]

sudo docker build -t yourjarname /var/build/

[/code]

 

Step 6: Running Docker Container of Your Jar

[code]

#define your port below
sudo docker run -d –name yourjardockercontainername -p 8443:8443 -t yourjarname

[/code]

Here yourjardockercontainername can be used to see the logs of your spring boot jar file.

Command:

[code]
docker logs yourjardockercontainername.

[/code]

 

Docker useful commands for Beginners:

You can also find other useful docker commands here.

Exit mobile version