Şuayb's BlogŞuayb's Blog
Home
Categories
Games
MediumAboutContact
Language
Theme
    1. Blog
    2. Programming
    3. Spring Boot Docker Integration

Spring Boot Docker Integration

PublishedFebruary 21, 2025
UpdatedFebruary 22, 2025
Reading time3 min read
JavaKotlinSpring BootDockerContainerizationJib
XLinkedInFacebook
Spring Boot Docker Integration

Loading likes...

Spring Boot provides multiple ways to containerize applications efficiently using Docker, Buildpacks, and Jib. This guide explores different approaches to building and deploying Spring Boot applications with Docker.


Last updatedFebruary 22, 2025

Total viewsLoading hits...

Previous articleSpring Boot Kubernetes IntegrationNext articleSpring Boot Config Server
Şuayb Şimşek

Written by

Şuayb Şimşek

Backend-focused fullstack developer sharing practical notes on Spring Boot, security, microservices, and cloud-native architecture.

Expertise

  • Spring Boot
  • Go
  • Microservices
  • Next.js
  • Cloud Native

Connect

GitHubLinkedInMedium

Related posts

Spring Boot Kubernetes Integration
Programming

Spring Boot Kubernetes Integration

Learn how to deploy Spring Boot applications on Kubernetes for scalable, containerized microservices.

February 21, 20253 min read
JavaKotlinSpring BootKubernetesMicroserviceContainerization
Spring Boot Configuration Properties
Programming

Spring Boot Configuration Properties

Learn how to use @ConfigurationProperties for type-safe configuration, validate settings with @Validated, and manage environment-specific values with profile-specific application-{profile}.yml files.

February 4, 20263 min read
JavaKotlinSpring BootConfiguration
Spring Boot GraphQL JWE Authentication
Programming

Spring Boot GraphQL JWE Authentication

Learn how to secure your Spring Boot GraphQL APIs with stateless encrypted JWTs (JWE) while persisting user identities and roles in a JPA-backed database.

May 17, 20256 min read
JavaKotlinSpring BootSecurityJWTJWEGraphQL

About

Articles on Spring Boot, microservices, security, and more.

ContactStart here

Latest posts

  • Captain Tsubasa 2: World Fighters
  • Captain Tsubasa: Rise of New Champions
  • Spring Boot Configuration Properties
  • Spring Boot GraphQL JWE Authentication
  • Spring Boot JWE Authentication with JPA

Top topics

JavaKotlinSpring BootJWEJWTMicroservice

Subscribe

Get practical backend + fullstack notes when new articles are published.

Social

© 2024-2026 Şuayb's Blog. All rights reserved.

🌟 Why Use Docker for Spring Boot?

In this section, we clarify Why Use Docker for Spring Boot? and summarize the key points you will apply in implementation.

  • Portable Deployment: Run applications consistently across environments.
  • Scalability: Easily scale and manage containerized applications.
  • Lightweight and Efficient: Optimize resource utilization with minimal overhead.
  • DevOps Friendly: Seamlessly integrate with CI/CD pipelines.

📋 Prerequisites

Ensure you have the following:

  • ☕ Java Development Kit (JDK) 17+
  • 📦 Maven or Gradle installed
  • 🐳 Docker installed and running

🛠️ Step 1: Add Dependencies

To enable Docker support, add the Spring Boot Maven Plugin, Jib Plugin, and Spring Boot Web Starter to your build tool.

Maven:

XMLpom.xml
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>jib-maven-plugin</artifactId>
            <version>3.3.2</version>
        </plugin>
    </plugins>
</build>

Gradle:

GROOVYbuild.gradle
plugins {
    id 'org.springframework.boot' version '3.2.0'
    id 'com.google.cloud.tools.jib' version '3.3.2'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
}

To enable Docker support, add the Spring Boot Maven Plugin and Jib Plugin to your build tool.

Maven:

XMLpom.xml
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>jib-maven-plugin</artifactId>
            <version>3.3.2</version>
        </plugin>
    </plugins>
</build>

Gradle:

GROOVYbuild.gradle
plugins {
    id 'org.springframework.boot' version '3.2.0'
    id 'com.google.cloud.tools.jib' version '3.3.2'
}

🛠️ Step 2: Create a Simple Spring Boot Application

Define a REST endpoint to deploy inside a Docker container.


▶️ Step 3: Build and Run a Docker Image

In this section, we clarify Step 3: Build and Run a Docker Image and summarize the key points you will apply in implementation.

Option 1: Using Buildpacks

Spring Boot provides built-in support for creating Docker images without a Dockerfile using Buildpacks.

BASH
mvn spring-boot:build-image
BASH
gradle bootBuildImage

Run the container:

BASH
docker run --rm -p 8080:8080 myproject:0.0.1-SNAPSHOT

Option 2: Using Jib

Jib allows building optimized container images without a Docker daemon.

BASH
mvn jib:dockerBuild
BASH
gradle jibDockerBuild

Run the Jib-built container:

BASH
docker run --rm -p 8080:8080 myproject:0.0.1-SNAPSHOT

▶️ Running the Application

Once the container is running, test the REST API:

BASH
curl -X GET http://localhost:8080/hello

Expected Output:

PLAINTEXTsnippet.txt
Hello from Spring Boot running in Docker!

🏁 Conclusion

You now have a practical Spring Boot Docker Integration implementation with a clear, production-friendly Spring Boot structure. As a next step, adapt configuration and tests to your own domain, then validate behavior under realistic traffic and failure scenarios.

JAVADockerApplication.java
package com.example.docker;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DockerApplication {

    public static void main(String[] args) {
        SpringApplication.run(DockerApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello() {
        return "Hello from Spring Boot running in Docker!";
    }
}
KOTLINDockerApplication.kt
package com.example.docker

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication
@RestController
class DockerApplication {

    @GetMapping("/hello")
    fun hello(): String = "Hello from Spring Boot running in Docker!"
}

fun main(args: Array<String>) {
    runApplication<DockerApplication>(*args)
}