DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Frameworks
  4. Dockerizing Spring Boot Application

Dockerizing Spring Boot Application

Take a look at how you can create a Docker container and image for your Spring Boot application in just a few simple steps.

Deepak Kumar user avatar by
Deepak Kumar
·
Aug. 21, 18 · Tutorial
Like (10)
Save
Tweet
Share
45.57K Views

Join the DZone community and get the full member experience.

Join For Free

This blog will help you in Dockerizing your Spring Boot application. A sample project is commited on Github using this tutorial. Click here to check the project.

Prerequisites:

  • Docker must be installed on your machine.
  • You have basic knowledge of Spring profiling.

1. Add DockerFile & Entrypoint in Your Project:

Create src/main/docker  in your project and add DockerFile in your project. This file is not a project-specific file; all you need to change is MAINTAINER  and LOG_PATH . We are using openjdk8-slim as the base image. For security, we are creating a separate user for the container.

Change your BOOTAPP_JAVA_OPTS according to your need.

Image title

  • Add the entrypoint file wrapper.sh  in src/main/docker 

#!/usr/bin/env bash
exec java -Djava.security.egd=file:/dev/./urandom $BOOTAPP_JAVA_OPTS -jar  -Dspring.profiles.active=$ENV_NAME $BOOTAPP_PATH --server.port=$SERVER_PORT > /dev/stdout 2>&1


2. Update Your POM:

  • Add the Docker registry in the properties section of your POM. This is where your Docker images will be pushed.
<docker.registry>javatechy</docker.registry>


  • At first, add the docker-maven-plugin by Fabric8 to your project’s POM:Image title


3. Build The Image:

To build the image do mvn clean install. This will build your Docker image and store it in your local Docker repository.

To check your image run docker images  .  

Image title

4. Push Your Image:

To Push your image use mvn docker:push . This will push your image to your remote container registry.

5. Play with Your Container:

To start your built container:

docker run -it -p 9000:8000 --name docker_boot_app -d javatechy/dockboot


This will start your container on port 9000 . 

Browse your application on http://localhost:9000/docker_boot/health

Check your container using docker ps -a 

Image title



In this blog, we learned how we can dockerize your spring boot application using docker-maven-plugin.




Spring Framework Spring Boot application Docker (software)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Configure Kubernetes Health Checks
  • Detecting Network Anomalies Using Apache Spark
  • Host Hack Attempt Detection Using ELK
  • Introduction Garbage Collection Java

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: