Featured Article

Master Spring Boot Docker Container Example: Run and Deploy Like a Pro

Kenneth Jul 13, 2026

Spring Boot, a popular framework for building Java applications, integrates seamlessly with Docker, the widely-used containerization platform. Combining these two enables faster application development, simplified deployment, and ease of scalability. Let's dive into a practical example of running a Spring Boot application inside a Docker container.

System Design: Why We Use Docker 🐳📦
System Design: Why We Use Docker 🐳📦

Before we start, ensure you have Docker and Docker Compose installed on your system. You'll also need a basic understanding of Spring Boot and Docker fundamentals.

Spring Boot Docker- How To Deploy Spring Boot Application In Docker?
Spring Boot Docker- How To Deploy Spring Boot Application In Docker?

Setting Up the Spring Boot Application

For this example, let's imagine we're using a simple "Hello, World!" Spring Boot application. If you don't have one already, you can create a new project using start.spring.io or your favorite IDE with the "Web" dependency.

Balcon
Balcon

Add the following code to your application.properties file to expose the application on port 8080:

``` server.port=8080 ```

Packaging the Application as a JAR

Why Every Developer Needs Docker 🐳📦
Why Every Developer Needs Docker 🐳📦

Once you're satisfied with your application, package it as an executable JAR by adding this to your pom.xml file:

```xml org.springframework.boot spring-boot-maven-plugin ```

Run the following Maven command to create the JAR file:

``` mvn clean package ```

Creating the Dockerfile

25 Cute Spring Rubber Boot Planter Ideas for Your Garden
25 Cute Spring Rubber Boot Planter Ideas for Your Garden

Navigate to your project's root directory and create a new file named Dockerfile. This file will instruct Docker on how to build your container image. Add the following content:

```Dockerfile FROM openjdk:8-jdk-alpine VOLUME /tmp ARG JAR_FILE COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar"] ```

This Dockerfile uses the OpenJDK 8 image as the base, copies the JAR file into the container, and sets the entrypoint to run the application.

Building the Docker Image

Java + Spring Boot + Microservices Example - Step by Step Guide
Java + Spring Boot + Microservices Example - Step by Step Guide

With the Dockerfile in place, you can now build your Docker image. Run the following command in your project's root directory, replacing hello-world with your desired image name:

``` docker build -t hello-world . ```

This command builds the Docker image and tags it with the name hello-world.

Best 15 Spring Container Garden Design Ideas to Try
Best 15 Spring Container Garden Design Ideas to Try
a close up of a metal object on the ground near a brick wall and grass
a close up of a metal object on the ground near a brick wall and grass
How to Make Rain Boot Planters That Are Adorable
How to Make Rain Boot Planters That Are Adorable
a wooden shelf with several different types of items on it next to a brick wall
a wooden shelf with several different types of items on it next to a brick wall
an old pair of boots with flowers in them
an old pair of boots with flowers in them
25 Creative Spring Boot Planter Ideas for Charming Garden Decor
25 Creative Spring Boot Planter Ideas for Charming Garden Decor
a bunch of boots that are sitting on a wooden table in front of a building
a bunch of boots that are sitting on a wooden table in front of a building
Top 10 Advanced Courses for Full Stack Java Developers
Top 10 Advanced Courses for Full Stack Java Developers
a yellow rubber boot with pink flowers in it and green leaves sticking out of the boots
a yellow rubber boot with pink flowers in it and green leaves sticking out of the boots

Running the Docker Container

Now that you have your Docker image, you can run it using the following command:

``` docker run -p 49000:8080 hello-world ```

This command maps port 49000 on your host to port 8080 inside the container and runs the container image. To verify that your application is running, open a web browser and navigate to http://localhost:49000. You should see your "Hello, World!" message.

That's it! You've successfully created and run a Spring Boot application within a Docker container. This setup allows for easier deployment and scalability of your applications. Now, explore more Docker features like volumes, networking, and multi-container setups to further enhance your development workflow.