DevOps
Containerizing Java Apps: Docker and Kubernetes
The days of deploying a WAR file to a Tomcat instance on a virtual machine are fading. Most Java shops are moving to containers. I started Dockerizing my Spring Boot apps a couple of years ago. The biggest issue with Java in containers was that the JVM didn’t understand cgroups limits. If you set a memory limit in Docker, the JVM would still use its own `-Xmx` setting, often ignoring the container limit. Thankfully, modern JVMs (JDK 10+) have container awareness. Now, I use `-XX:+UseContainerSupport` and `-XX:MaxRAMPercentage=80.0`. On Kubernetes, Java apps behave well. The graceful shutdown is important—Spring Boot’s graceful shutdown feature combined with Kubernetes’ `preStop` hooks ensures that requests are finished before the pod is terminated. It’s a lot to learn, but container orchestration is now a required skill for Java devs.
3,285
Views
138
Words
1 min read
Read Time
May 2025
Published