Kubernetes Series - Dockerize the Application

If you have any questions or encounter any issues, feel free to leave a comment below!
I’ll respond or update the content accordingly. “:)”


🚀 Table of Contents

  1. Create a Spring Boot Project
  2. ➡️ Dockerize the Application
  3. Deploy to Kubernetes (NodePort)
  4. Configure Ingress Routing
  5. Install Local GitLab
  6. Connect Git to GitLab
  7. Install ArgoCD
  8. Create ArgoCD Application
  9. Setup GitOps Flow
  10. Setup GitLab Runner
  11. Auto Image Tag & Sync

🐳 Step 2: Dockerize the Spring Boot Application

Now that we have our Spring Boot application ready, let’s containerize it using Docker so that we can deploy it easily to Kubernetes.


🧾 2.1 Create a Dockerfile

Inside the root of your k8sdemo project, create a file named Dockerfile with the following content:

FROM eclipse-temurin:17-jdk => based on Max OS M1

FROM eclipse-temurin:17-jdk

WORKDIR /app

COPY target/k8sdemo-0.0.1-SNAPSHOT.jar app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "app.jar"]

image-20250728144030300

This Dockerfile does the following:

  • Uses a lightweight JDK 17 image
  • Copies the built JAR file into the image
  • Exposes port 8080
  • Runs the application with java -jar

🧱 2.2 Build the JAR

In order to use the Dockerfile, you need to build your application JAR first:

./mvnw clean package -DskipTests

This will generate target/demo-0.0.1-SNAPSHOT.jar.

image-20250728143759494

image-20250728143541164

🐳 2.3 Build the Docker Image

Run the following command to build the Docker image:

docker build -t k8sdemo:latest .

Make sure you’re in the root directory of your project where the Dockerfile is located.

image-20250728144132876

🧪 2.4 Test the Docker Image

To verify that the Docker image works correctly, run it locally:

docker run -p 8080:8080 k8sdemo:latest

image-20250728144211013

Open your browser or use curl to test the endpoint:

http://localhost:8080/hello

You should see the response from your Spring Boot application.

image-20250728144226726


댓글남기기