Why do I see (Defunct) Zombie Processes?

Normally, the init process (PID 1) inside a Docker container is responsible for managing other processes. However, when your container starts, your application process start as PID 1, it creates a potential issue and creates defunct (zombie) processes.

What is a Defunct process?

Imagine a scenario where npm run start spawns child processes (for example, your application logic) during startup. When these child processes finish their tasks, and they do not convey their Exit status to their parents, they are referred to as 'Zombie processes'. While zombie processes might not cause immediate issues, their accumulation can lead to resource exhaustion over time. It's best to address them proactively.

In a typical Linux system, the init process (PID 1) would automatically clean up these zombies. However, since your container uses npm run start as PID 1, it lacks the ability to perform this cleanup because it's running as a separate process. As a result, these zombie processes accumulate over time, consuming resources and potentially impacting your container's performance.

How to remove the Defunct processes?

Qualys recommends using tini process in order to effectively reap the Defunct (Zombie) processes. You can initiaite tini process while launching a container in your environment. This ensures that a minimal init process like tini is launched as PID 1. This dedicated init process is responsible for managing child processes and cleaning up zombies.

Usage Examples
Docker Run:
Use with docker run -it --init <image> or by adding tini to your Dockerfile.

Docker Run:
Use with podman run -it --init <image> or by adding tini to your Dockerfile.

Dockerfile:
Example: ENTRYPOINT ["/usr/bin/tini", "--", "/your/program"]