Deploying Spring Boot Microservices with Docker: Step-by-Step

Published 2026-05-17 · By Shubham Bhati · Backend Engineer at AlignBits LLC

Spring Boot Docker Deployment

Published 2026-05-17 by Shubham Bhati — Backend Engineer (Java 17, Spring Boot, Microservices).

We've all been there - stuck with a Spring Boot application that's difficult to deploy and manage in production. As backend engineers, we know that containerization is key to solving this problem. That's where Spring Boot Docker deployment comes in. By dockerizing our Spring Boot applications, we can ensure consistent and reliable deployments. In our experience, using Spring Boot 3.2 and Java 21, we've seen significant improvements in deployment times and application performance.

Introduction to Spring Boot and Docker

To get started with Spring Boot Docker deployment, we need to understand the basics of Docker and how it works with Spring Boot. Docker is a containerization platform that allows us to package our application and its dependencies into a single container. This container can then be deployed to any environment that supports Docker. Spring Boot, on the other hand, is a popular framework for building Java-based web applications. By combining Spring Boot and Docker, we can create a seamless deployment experience for our applications. For example, we can use the following Dockerfile to create a Docker image for our Spring Boot application:

FROM openjdk:21-jdk-alpine
ARG JAR_FILE=target/myapp.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

This Dockerfile uses the official OpenJDK 21 image and copies our Spring Boot application jar file into the container.

Setting up Docker for Spring Boot

Before we can start using Docker with our Spring Boot application, we need to set up Docker on our machine. This involves installing Docker Desktop or Docker Engine, depending on our operating system. Once Docker is installed, we can verify that it's working by running the command docker --version. We can also use the official Docker documentation to get started with Docker.

Creating a Docker Image for Spring Boot

To create a Docker image for our Spring Boot application, we need to create a Dockerfile that defines the build process for our image. This Dockerfile should include instructions for copying our application code, installing dependencies, and setting the entry point for our application. For example:

// MyApplication.java
@SpringBootApplication
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}

We can then use the following Dockerfile to create a Docker image for our application:

FROM openjdk:21-jdk-alpine
ARG JAR_FILE=target/myapp.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

This Dockerfile uses the official OpenJDK 21 image and copies our Spring Boot application jar file into the container.

Deploying Spring Boot Microservices with Docker

Once we have created a Docker image for our Spring Boot application, we can deploy it to any environment that supports Docker. This can include local machines, cloud platforms, or container orchestration tools like Kubernetes. For example, we can use the following command to deploy our Docker image to a local machine:

docker run -p 8080:8080 myapp

This command starts a new container from our myapp image and maps port 8080 on the host machine to port 8080 in the container.

Kubernetes and Spring Boot

Kubernetes is a popular container orchestration tool that can be used to deploy and manage Spring Boot applications. By using Kubernetes, we can automate the deployment, scaling, and management of our applications. For example, we can use the following deployment.yaml file to deploy our Spring Boot application to a Kubernetes cluster:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: myapp:latest
        ports:
        - containerPort: 8080

This deployment.yaml file defines a deployment for our myapp application, with three replicas and a container port of 8080.

Common Mistakes in Spring Boot Docker Deployment

Here are some common mistakes to avoid when deploying Spring Boot applications with Docker:
* Not using the correct base image for our Docker image
* Not copying the correct files into the Docker image
* Not setting the correct entry point for our application
* Not exposing the correct ports for our application
* Not using a container orchestration tool like Kubernetes

Frequently Asked Questions

What is the best way to deploy a Spring Boot application with Docker?

The best way to deploy a Spring Boot application with Docker is to use a container orchestration tool like Kubernetes. This allows us to automate the deployment, scaling, and management of our applications.

How do I troubleshoot issues with my Spring Boot Docker deployment?

To troubleshoot issues with our Spring Boot Docker deployment, we can use the official Docker documentation to check the logs for our containers. We can also use the docker exec command to execute commands inside our containers.

What are the benefits of using Docker with Spring Boot?

The benefits of using Docker with Spring Boot include consistent and reliable deployments, improved application performance, and simplified management of our applications. We can also use Docker to create a seamless development experience for our applications.

Can I use Docker with other Java frameworks?

Yes, we can use Docker with other Java frameworks, such as Java EE and Micronaut. Docker is a containerization platform that can be used with any Java application, regardless of the framework or library used.

Conclusion

In conclusion, deploying Spring Boot microservices with Docker is a great way to ensure consistent and reliable deployments. By using Docker, we can create a seamless deployment experience for our applications and improve their performance. We can also use container orchestration tools like Kubernetes to automate the deployment, scaling, and management of our applications. To get started with Spring Boot Docker deployment, we can check out the official Spring Boot documentation and the official Docker documentation.


Spring Boot Docker Deployment in production

Further Reading


Written by Shubham Bhati — Backend Engineer at AlignBits LLC, specializing in Java 17, Spring Boot, microservices, and AI integration. Connect on LinkedIn, GitHub, or read more at shubh2-0.github.io.

#docker #springboot #devops #microservices

Related Articles

RabbitMQ with Spring Boot: A Complete Messaging Tutorial
In our production environment, we've seen firsthand how a well-designed messaging system can make all the difference in handling high volume
Java Microservices Architecture: A Complete Guide for 2026
We've all been there - stuck with a monolithic application that's become too complex to maintain. In our production environment, we once had
Spring Data JPA Advanced Queries: Specifications, Projections, and Native SQL
We've all been there - stuck with a complex query in our Spring Boot application, trying to figure out how to use Spring Data JPA to fetch t