How to Run Simple Spring Boot Application in Docker..
Build & Deploy using Docker
👋 Hi Everyone Welcome to another Techie Talk! 😊
Today I’m going to show you how to Run a Simple hello World spring boot application on Docker. lets get in to rest

components That needed,
- Docker (install to the PC)
- IDE (eclipse/IntelliJ)
- Java (Install to the pc)
Step 01: Create Simple Spring boot web application

Open this project from your IDE and add a simple REST API

Check you pom.xml whether it is include the “spring-boot-maven-plugin”
spring-boot-maven-plugin : It responsible for create single executable jar file

Build the project with maven goal :clean compile install

After Build success check the target folder whether it is created the jar file.

Run this web application as a console application using cmd
Goto HelloWorld-0.0.1-SNAPSHOT location open cmd and run this command
java -jar HelloWorld-0.0.1-SNAPSHOT.jar

Make sure the weather program is running correctly.
Step 02: Create Docker Image
Create Dockerfile inside the root folder and add these lines

1st line : From → We build our Docker image on top of that JDK.(Parent Image)
2nd line: Volume → Tomcat works on this location, so this is needed for springboot application
3rd line: Add → Our Jar file name
4th line → Entry point our application to run. It tells Docker how to run this application
Step 03: Build Docker Image
Go to Project folder and Run this command on cmd.
✅“docker build -t helloworld .”✅
helloworld is our docker image name (Note: don’t use capital letters)
The dot indicates that our Dockerfile is in the same location

Verify that your Docker image has been successfully built.
✅“docker image ls”✅

Step 04: Run Docker Container
First you have to do a port mapping there reason because your application is running in a virtual environment and when you try to access from your host machine it might not work so that you have to do a port mapping from your host machine to the Docker machine.
✅“docker run -p8080:8080 helloworld”✅

Verify whether your application has successfully run in your browser

Open Your Docker GUI to see more info

Step 05: Stop Docker Container Running
Use this command to see currently running docker containers
✅“docker ps”✅

Copy the Container ID and Run this command
✅docker container stop “copied ID”✅
- Note : When you need to start again, do not run that step 4 docker command of docker run, because it will create a new docker container. You don’t need new one because you already have one, we can start that one using the same process that we used to stop it. Use this command.
✅docker container start “copied ID”✅
Using this command, you can find the running or not running containers
✅“docker ps -a”✅
I hope you learned something… If so, give a small clap and click FOLLOW for more interesting topics… 👏👏👏👏👏👏👏
- GitHUB Docs : TechnoWebbies