Skip to content

Demonstration of containerizing a Spring Boot REST application using Docker. Leveraging OpenJDK 17, Maven, and a custom Dockerfile, this project showcases best practices for building, packaging, and running lightweight Docker containers.

License

Notifications You must be signed in to change notification settings

GRB-Workspace/Docker-Intro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Docker Intro Logo

Docker Intro

This project demonstrates a sample Docker container build and run configuration for a Spring Boot REST application. Using OpenJDK 17, Maven, and a custom Dockerfile, it serves as an example for containerizing Java applications.
Explore the repository »

· Report Bug · Request Feature


Notes

For additional insights on the Docker configurations and more, please refer to the following handwritten notes:
Handwritten Docker & Azure VM Setup Note
Handwritten LoadBalancing and Kubernetes Intro Note


Table of Contents
  1. About The Project
  2. Getting Started
  3. Project Structure
  4. Documentation
  5. Contributing
  6. License
  7. Contact

About The Project

Docker Intro Sample Project is a demonstration of containerizing a Spring Boot REST application using Docker. The project includes:

  • A Dockerfile that builds an image based on OpenJDK 17.
  • A sample Spring Boot REST controller that exposes a simple endpoint.
  • Maven build configurations where the final JAR name is customized using <finalName>Hello</finalName> in the pom.xml.

This project is designed to help developers quickly learn how to build, package, and run Docker containers for Java applications in a professional and scalable manner.

Core Features

  • Containerization with Docker
    Utilizes a Dockerfile to package the application into a lightweight container.

  • Spring Boot REST Controller
    Provides a sample endpoint to verify Docker container functionality:

    @RestController
    public class DockerTestController {
        @GetMapping("/docker")
        public String getDocker() {
            return "Docker Test Successful!";
        }
    }
  • Maven Build Process
    Demonstrates a Maven-based build process with custom JAR naming for consistency in deployments.

(back to top)


Built With

  • Java 17 – Utilized via the OpenJDK 17 base image.
  • Spring Boot – Framework for building the REST controller.
  • Maven – Build and dependency management tool.
  • Docker – Containerization platform.

(back to top)


Getting Started

Follow these instructions to set up and run the Docker Intro Sample Project on your local machine.

Prerequisites

  • Java JDK 17 or later.
  • Maven (ensure you have Maven installed and configured).
  • Docker – Installed and running on your system.
  • IntelliJ IDEA (or your preferred IDE).

Installation and Setup

  1. Clone the repository:

    git clone https://github.com/GRB-Workspace/Docker-Intro.git
    cd Docker-Intro
  2. Open the project in IntelliJ IDEA.

  3. Clean and Package the Project:

    Open your terminal in the project root and run:

    mvn clean
    mvn package

    This will clean your project and package your Spring Boot application into a JAR file (named Hello.jar as defined in your pom.xml).

(back to top)


Docker Usage

The project includes a Dockerfile with the following configuration:

# Use OpenJDK 17 as base image
FROM openjdk:17-jdk-slim

# Add application JAR file to the container
ADD target/Hello.jar app.jar

# Expose the port that the application will run on
EXPOSE 8080

# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]

Building and Running the Docker Image

  1. Build the Docker image:

    docker build -t docker-intro .
  2. Run the Docker container:

    docker run -p 8080:8080 docker-intro
  3. Test the application:

    Open your web browser or use cURL/Postman to access the endpoint:

    http://localhost:8080/docker
    

    You should receive the following response:

    Docker Test Successful!
    

(back to top)


Project Structure

Docker-Intro/
├── src/
│   └── main/
│       ├── java/
│       │   └── me.grbulegoda.dockerintro/
│       │       └── DockerTestController.java
│       └── resources/
│           └── application.properties
├── target/
│   └── Hello.jar
├── Dockerfile
├── pom.xml
└── README.md

(back to top)


Documentation

For an in-depth explanation of the Docker configurations and best practices, please refer to my detailed guide on Medium:

(back to top)


Contributing

Contributions are welcome! If you have suggestions for improvements, bug fixes, or new features, please fork the repository and create a pull request. For any issues, feel free to open an issue on GitHub.


License

Distributed under the MIT License. See the LICENSE file for details.

(back to top)


Contact

Gayanuka Bulegoda
PortfolioGitHub


© 2025 Gayanuka Bulegoda


About

Demonstration of containerizing a Spring Boot REST application using Docker. Leveraging OpenJDK 17, Maven, and a custom Dockerfile, this project showcases best practices for building, packaging, and running lightweight Docker containers.

Topics

Resources

License

Stars

Watchers

Forks