It’s entirely possible to get your Spring Boot application up and running in docker in less than 10 minutes.

Let’s run through this process first in theory, then in practice. We will start by covering what we are trying to achieve, followed by installing some dependencies and making sure everything is in place to hit the ground running.

By the end we will have a fully working Spring boot application deployed to your local docker installation and we will have it running with health checks.


To run our application we are going to need: 1. Webserver & Application 2. Host & Execution environment

Below we can see a Standard 4 tier deployment of a Java app. The biggest issue with this setup is that of tight coupling between our app and the host.

We generally end up being tied to whatever Java version the Operating System is running, this limits the version of Tomcat which can be deployed and also the version of Java we can use in our code.

In the above example we have a Hello World & Goodbye World app deployed to the one Tomcat installation. This creates a costly migration challenge as we need to migrate both apps and potentially have to coordinate with operations teams around Java versions, Tomcat versions and even OS limitations.

Contrast this with our new setup where we have installed Docker to sit between the Operating System and the App environment.

Now we can support multiple variants of Java, Tomcat and deploy/restart independently of the other app. We also get the added benefit that should one app break, the other is isolated in its own app environment.

Creating an App

First thing we need to perform to get started is to install Docker.

With that complete you will need to create a new Spring Boot App using the Initializr either through your IDE of choice or the App.

The only items to select when creating the Spring Boot app are Spring Web and Actuator (for health endpoint)

Go ahead and start the application and ensure it runs as expected, navigate to http://localhost:8080/actuator/health and ensure the response shows the app as “UP”

    "status": "UP"

Creating Docker Image

Now we have a healthy and building application we are going to create the docker image from the Application.

Create a new file called Dockerfile in the root of the project and paste in the following

FROM openjdk:8-jre


COPY /build/libs/docker-app-*.jar /opt/fxqlabs-oss/docker-app/docker-app.jar

HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8080/actuator/health || exit 1


Lets quickly step through the Dockerfile to understand it further:

Firstly we use the FROM directive to define which base image we use, in this case its a simple OpenJDK docker image.

We use the EXPOSE directive to define that Tomcat will be available on port 8080

We use the COPY directive to copy the file from our local folder /build/libs/…jar (The build output artifact) and we put it into the docker images /opt/fxqlabs-oss/docker-app/ folder. This bakes the file into the image and will be run on image start.

We use the HEALTHCHECK directive to define a simple CheckHealth activity, simply we are going to use curl to poll the actuator/health endpoint to ensure it responds. Note we don’t check if its up or down here, just that curl exits without error.

Finally we use the ENTRYPOINT directive to define what command we should run when the container starts. In this example we simply send:

java -jar /opt/fxqlabs-oss/docker-app/docker-app.jar

This starts the Java application and runs it, exposing the app on 8080.

Building and Running

Let’s build the image, open up a terminal/cmd window and run

docker image build -t docker-app:snapshot .

Finally lets start a container from the image with the following command

  • -p (Declares which port to map our image port we map local port 8081 to 8080 in the container which is tomcat)
  • -d (Run the container detached from the console)
  • --name (What we should call the container once run
docker container run -p 8081:8080 -d --name docker-app docker-app:snapshot

Finally you can now load the application and it should be up!



During this article we covered how quickly you can setup a new application in docker. Once completed we can now develop our new application and be ready to deploy to any docker host.

  • We simply created a new Spring Boot App using the Initializr either through your IDE of choice or the App.
  • We added Actuator to it for health checking
  • We added a Dockerfile to define our image and copy our built artifact into the image.
  • We ran the image as a container on our local machine.

All code and the sample application is available in the Git repo

The repo also includes a bitbucket pipeline template showing how to build and deploy your app to Docker-Hub, along with a docker-compose template to run it.

Simply checkout the project and run docker-compose up -d to see it in action!