Do you want to build a Java application and run it in Docker? Do you know what the best practices are for building Java containers with Docker? In the following quick checklist, I’ll provide you with best practices for building production-grade Java containers designed to optimize and secure Docker images to be put into production environments. Building a simple Java container image Let’s start with a simple Dockerfile. When building a Java container, we often have something like the following.
In a previous article, I mentioned the problem of Java program containers generating a lot of zombie processes. Today I ran into it again, but in a different way. The zombie processes are also generated by a bash script, but this script is executed in the K8S readinessProbe and livenessProbe, not by the java program itself. Let’s look at some failure diagrams. You can see that there are many timeout processes that are not cleaned up after execution.
Recently I encountered a problem, a Java process using Runtime().exec() to execute script files, creating a large number of zombie processes, while the Java process is running in the container. At that time, I saw this situation on the Host machine, and I could see that there were a large number of zombie processes. Locate the zombie process by ps aux | grep Z. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2518 0.