DEV Community

Cover image for Containerize A Spring Boot App with Docker
scottshipp
scottshipp

Posted on Edited on Originally published at code.scottshipp.com

Containerize A Spring Boot App with Docker

Who this tutorial is for

This tutorial is for anyone who is wondering how to take a Spring Boot 2 application and containerize it with Docker.

Prerequisites

Before you begin, either make sure you have an existing Spring Boot 2 application, or if you don’t, I recommend going through the Spring Guide “Building a RESTful web service” with Spring Boot.

Once you have that, return here.

Video Version

As an added bonus, check out the end of this tutorial, where I’ve placed a video version of all of this.

Step 1. Add a Dockerfile

First, add a text file to the root directory of your application named “Dockerfile.”

Copy and paste the following into it:

FROM openjdk:11
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026 🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026

NOTE: if you are using Java 8, or another version of Java, be sure to select the correct base for your image in the “FROM” line (line 1). You can find other openjdk container bases at Docker Hub.

You may also be happy to know that there’s a Spring Guide titled “Spring Boot with Docker” where you can find more information about Dockerfiles and Spring Boot.

Step 2. Build an image

Next, you will build an image. Open a terminal, navigate to the root directory of your application, and type:

docker build -t {tag}
🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026 🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026

You can read more about tags in the Docker documentation.

If you plan to use Docker Hub, then it’s common to use your Docker Hub username. For example, I used this command on my example:

docker build -t scottashipp/helloworld
🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026 🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026

Step 3. Create and run a container

Now that you have built an image, you can create and run a container from that image.

In the same directory, type:

docker run -p 8080:8080 {tag}
🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026 🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026

If you forgot how you tagged your image, try listing images:

docker image ls
🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026 🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026

Assuming you find your tag, and run it correctly (for example I used “docker run -p 8080:8080 scottashipp/helloworld”), you should see Spring Boot start up, and the familiar “Started application . . .” message.

In this tutorial

In this tutorial, you have:

  • Built and tagged a Docker image from an existing Spring Boot application
  • Created and ran a Docker container from the created image

Next Steps

Next, check out the video version! Make sure to like and subscribe!

Top comments (7)

🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026
 
barddoo profile image
Charles Fonseca •
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar

what does those lines do?

🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026
 
stealthmusic profile image
Jan Wedel •

They copy the built spring boot executable jar file from the target folder in your project into the docker image and rename it to app.jar.

🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026
 
barddoo profile image
Charles Fonseca •

Does it merge all jars into one, which is app.jar?

🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026 Thread
 
scottshipp profile image
scottshipp •

After you build, look in the target/ folder, you will see a jar named the name of your service + '-' + version. For example, if your service is named helloworld, and on version 0.1.0-SNAPSHOT it will be named helloworld-0.1.0-SNAPSHOT.jar.

This is the jar that will be copied into the Docker container as app.jar

🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026 Thread
 
barddoo profile image
Charles Fonseca •

Thank you for explain!

🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026 Thread
 
stealthmusic profile image
Jan Wedel •

And yes, all dependencies will be inside the one app.jar. This is usually done by the spring boot maven plug-in.

🔥 Jadwal & Hasil: scottshipp/containerize a spring boot app with docker ock - Info Live Streaming 2026
 
rophilogene profile image
Romaric P. •

Hi Scottshipp, thanks for sharing. I would really love to have your feedback on my how to deploy a containerized Spring Boot application on AWS with Qovery.