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
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
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.
-
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.
- 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.
Follow these instructions to set up and run the Docker Intro Sample Project on your local machine.
- 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).
-
Clone the repository:
git clone https://github.com/GRB-Workspace/Docker-Intro.git cd Docker-Intro
-
Open the project in IntelliJ IDEA.
-
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).
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"]
-
Build the Docker image:
docker build -t docker-intro .
-
Run the Docker container:
docker run -p 8080:8080 docker-intro
-
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!
Docker-Intro/
├── src/
│ └── main/
│ ├── java/
│ │ └── me.grbulegoda.dockerintro/
│ │ └── DockerTestController.java
│ └── resources/
│ └── application.properties
├── target/
│ └── Hello.jar
├── Dockerfile
├── pom.xml
└── README.md
For an in-depth explanation of the Docker configurations and best practices, please refer to my detailed guide on Medium:
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.
Distributed under the MIT License. See the LICENSE file for details.
Gayanuka Bulegoda
Portfolio • GitHub
© 2025 Gayanuka Bulegoda