Wednesday, August 12, 2026

How to run the spring boot application in containerd

 --https://share.google/aimode/C9Ncgh6YM4dFfs5Tt

Refer this blog to know how to create kubernetes master node & worker node

https://trythissolution.blogspot.com/2026/07/create-k8s-master-worker-node.html


To run a Spring Boot application directly in containerd without relying on Docker Desktop or the standard Docker CLI, you must use nerdctl (a Docker-compatible CLI for containerd) or ctr (the native, low-level containerd CLI). [1, 2, 3, 4]
Because ctr is designed solely for low-level debugging and cannot easily handle publishing ports, using nerdctl is the highly recommended approach for local development and testing. [1]

Step 1: Build the Spring Boot Image
Containerd runs standard OCI container images. First, build your application's JAR file using Maven or Gradle, and compile it into an image. [1, 2, 3, 4, 5]
1. Create a Dockerfile in your project root: [1]
dockerfile
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
COPY target/*.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
குறியீட்டைக் கவனமாகப் பயன்படுத்துங்கள்.
2. Package the app and build the image using nerdctl: [1]
bash
# Build the JAR file
mvn clean package

# Build the OCI container image directly into containerd
sudo nerdctl build -t spring-boot-app:latest .
குறியீட்டைக் கவனமாகப் பயன்படுத்துங்கள்.

Step 2: Run the Container
Option A: Using nerdctl (Recommended) [1, 2]
nerdctl features a command syntax identical to Docker, allowing you to expose network ports seamlessly. [1]
Run the image using the following command:
bash
sudo nerdctl run -d --name my-spring-app -p 8080:8080 spring-boot-app:latest
குறியீட்டைக் கவனமாகப் பயன்படுத்துங்கள்.
  • Use sudo nerdctl ps to view your running container.
  • Access your application at http://localhost:8080. [1]
Option B: Using ctr (Native containerd CLI) [1, 2]
The native ctr CLI does not automatically handle container networking or bridge port mapping. To make your application accessible from your host machine, you must instruct the container to share the host's network namespace (--net-host). [1, 2]
1. Import your image into the default containerd namespace:
If you built your image with Docker instead of nerdctl, export it as a tarball and load it into ctr:
bash
docker save spring-boot-app:latest -o spring-app.tar
sudo ctr images import spring-app.tar
குறியீட்டைக் கவனமாகப் பயன்படுத்துங்கள்.
2. Run the container with host networking: [1]
bash
sudo ctr run --net-host --detached docker.io/library/spring-boot-app:latest my-spring-app
குறியீட்டைக் கவனமாகப் பயன்படுத்துங்கள்.
  • Note: Ensure your application.properties does not conflict with any existing services running on port 8080 on your host machine.
  • Use sudo ctr containers list and sudo ctr tasks list to manage the process. [1, 2]

Step 3: Verify the Running Application
You can check the container startup logs to ensure your Spring Boot banner loads successfully: [1]
  • For nerdctl: sudo nerdctl logs my-spring-app
  • For ctr: sudo ctr tasks logs my-spring-app

If you plan to scale this implementation, let me know:
  • Will you be orchestration-managing this application via Kubernetes (K8s) or K3s?
  • Do you require a multistage build configuration to reduce overall container size?
  • Do you need assistance setting up health checks or environment variables?

No comments: