Dockerizing Spring Boot Application: A Beginner’s Guide

Hello learners,
If you are reading How to Dockerize a Spring Boot App, I assume you already know what containerization is. If not, don’t worry—learn it in a simpler way by clicking here, or follow these steps below to dockerize your Spring Boot App.

Y…


This content originally appeared on DEV Community and was authored by RITIK KUMAR

Hello learners,
If you are reading How to Dockerize a Spring Boot App, I assume you already know what containerization is. If not, don’t worry—learn it in a simpler way by clicking here, or follow these steps below to dockerize your Spring Boot App.

You have your Spring Boot application up and running, and running Docker Desktop application.
Now, to containerization using Docker follow these steps,

1. First, create a .jar file of your Spring Boot application.

  • Open your terminal in the root directory and run the following command:

  • mvn clean package OR

  • If Maven is not installed, you can use the Maven wrapper. Run the following command: ./mvnw clean package (or use ./mvnw clean package -DskipTests to skip tests before building the .jar file).

2. Now that your .jar file is in the target folder, create your first Dockerfile.

  • Create a file named ‘Dockerfile’ (with no extension) in the root directory. Then add the following contents:
  • FROM openjdk:17-jdk-alpine
    WORKDIR /app
    COPY target/*.jar app.jar
    EXPOSE 8080
    ENTRYPOINT ["java","-jar","/app.jar"]

  • This will have instructions to install the necessary environment, execute your application, and expose the port where the app will run in the container (and on your host, with port mapping).

3. Now that you have a Dockerfile, build a Docker image by running the following command, run this cmd

  • docker build -t give_a_img_name .

4. Finally, run your Docker container using this command:

  • docker run --name give_con_name your-img-name
  • Now check you running container running using command: docker ps

  • By the way, this is my first blog ever, so don’t forget to comment your views, feedback, suggestions, or anything else!


This content originally appeared on DEV Community and was authored by RITIK KUMAR


Print Share Comment Cite Upload Translate Updates
APA

RITIK KUMAR | Sciencx (2025-03-31T18:17:29+00:00) Dockerizing Spring Boot Application: A Beginner’s Guide. Retrieved from https://www.scien.cx/2025/03/31/dockerizing-spring-boot-application-a-beginners-guide/

MLA
" » Dockerizing Spring Boot Application: A Beginner’s Guide." RITIK KUMAR | Sciencx - Monday March 31, 2025, https://www.scien.cx/2025/03/31/dockerizing-spring-boot-application-a-beginners-guide/
HARVARD
RITIK KUMAR | Sciencx Monday March 31, 2025 » Dockerizing Spring Boot Application: A Beginner’s Guide., viewed ,<https://www.scien.cx/2025/03/31/dockerizing-spring-boot-application-a-beginners-guide/>
VANCOUVER
RITIK KUMAR | Sciencx - » Dockerizing Spring Boot Application: A Beginner’s Guide. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/31/dockerizing-spring-boot-application-a-beginners-guide/
CHICAGO
" » Dockerizing Spring Boot Application: A Beginner’s Guide." RITIK KUMAR | Sciencx - Accessed . https://www.scien.cx/2025/03/31/dockerizing-spring-boot-application-a-beginners-guide/
IEEE
" » Dockerizing Spring Boot Application: A Beginner’s Guide." RITIK KUMAR | Sciencx [Online]. Available: https://www.scien.cx/2025/03/31/dockerizing-spring-boot-application-a-beginners-guide/. [Accessed: ]
rf:citation
» Dockerizing Spring Boot Application: A Beginner’s Guide | RITIK KUMAR | Sciencx | https://www.scien.cx/2025/03/31/dockerizing-spring-boot-application-a-beginners-guide/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.