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. Building Docker Image for a Spring Boot App With Jib

Building Docker Image for a Spring Boot App With Jib

Want to learn how to build a Docker image for a Spring Boot app? Check out this post to learn how with Jib.

Biju Kunjummen user avatar by
Biju Kunjummen
·
Jul. 23, 18 · Tutorial
Like (12)
Save
Tweet
Share
16.65K Views

Join the DZone community and get the full member experience.

Join For Free

I was pleasantly surprised by how easy it was to create a Docker image for a sample Spring Boot application using Jib.

Let me first explain Jib with an approach that I was using before.

I was creating Docker images using bmuschko's excellent Gradle-Docker plugin. After gaining access to a Docker daemon and a gradle dsl-based description of the Dockerfile or a straight Dockerfile, it would create the Docker image using a gradle task. In my case, the task to create the Docker image looks something like this:

task createDockerImage(type: DockerBuildImage) {
    inputDir = file('.')
    dockerFile = project.file('docker/Dockerfile')
    tags = ['sample-micrometer-app:' + project.version]
}

createDockerImage.dependsOn build


And, my Dockerfile derived from "java:8" base image:

FROM java:8
...


The Gradle-Docker-plugin made it simple to create a Docker image right from Gradle with the catch that the plugin needs access to a Docker daemon to create the image. Also, since the base "java:8" image is large, the final Docker image turns out to be around 705 MB on my machine. Again, this has nothing to do with the Gradle-Docker plugin, but this is based on my personal choice of base image.

Now, with Jib, all I have to do is to add the plugin:

plugins {
    id 'com.google.cloud.tools.jib' version '0.9.6'
}


Next, you will need to configure it to give the image a name:

jib {
    to {
        image = "sample-micrometer-app:0.0.1-SNAPSHOT"
    }
}


And, that is it. With a local Docker daemon available, I can create my Docker image using the following task:

./gradlew jibDockerBuild


Jib automatically selects a very lightweight base image. My new image is about 150 MB in size.

If I had access to a Docker registry, then, the local Docker daemon is not required; it can directly create and publish the image to a Docker registry!

Jib Gradle plugin provides an interesting task — jibExportDockerContext   to export out the Docker file. This way, if needed, a Docker build can be run using this Dockerfile. For my purposes, I wanted to see the contents of this file. It looks something like this:

FROM gcr.io/distroless/java

COPY libs /app/libs/
COPY resources /app/resources/
COPY classes /app/classes/

ENTRYPOINT ["java","-cp","/app/libs/*:/app/resources/:/app/classes/","sample.meter.SampleServiceAppKt"]


All in all, a very smooth experience, and Jib does live up to its goals. My sample project with Jib integrated with a Gradle build is available here.

Docker (software) Spring Framework Spring Boot app

Published at DZone with permission of Biju Kunjummen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Creating a Personal ReadMe for Scrum Masters With ChatGPT
  • What Is Docker Swarm?
  • How to Assess the Technical Skills of a Software Development Partner
  • 8 Proven Ways to Combat End-of-Life Software Risks

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: