Kubernetes equivalent of docker run --init
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
There is no direct Pod spec flag that is equivalent to Docker's --init. Docker --init inserts a tiny init process such as tini as PID 1 inside the container so signals are forwarded correctly and zombie child processes are reaped. In Kubernetes, the usual answer is to run an init process inside the container image or command line yourself.
Why Docker --init Exists
Inside a container, PID 1 has special responsibilities. If your application becomes PID 1 directly and does not handle Unix signals or child-process reaping properly, you can run into problems such as:
- orphaned zombie processes
- slow or incorrect shutdown on
SIGTERM - pods hanging during termination
Docker's --init flag solves that by inserting a tiny init process in front of your application.
Why Init Containers Are Not The Equivalent
Kubernetes has init containers, but they solve a different problem. Init containers run before the main container starts. They are for setup work such as fetching configuration or waiting for dependencies.
They do not remain as PID 1 for the main application process, so they are not the equivalent of Docker --init.
That distinction matters because this is one of the most common misconceptions around the topic.
The Practical Kubernetes Pattern
If you want Docker---init behavior in Kubernetes, package a minimal init process such as tini into the image and make it the container entrypoint.
A Dockerfile example:
Then your Pod spec can stay ordinary:
Now tini becomes PID 1 in the container and your application runs beneath it.
Using command In The Pod Spec
If the image already contains tini, you can also wire it in from the Pod spec.
This can be useful when you do not want to change the image entrypoint directly, though in many teams the image-level approach is cleaner.
When You May Not Need It
If your application is a single well-behaved process that handles SIGTERM correctly and does not spawn orphaned child processes, you may not need a separate init process at all.
For example, many modern Go services run fine as PID 1 because they handle signals explicitly and do not create child-process trees that require reaping.
So the real question is not "what is the Kubernetes equivalent?" but "does this process actually need an init shim?"
Test Shutdown Behavior, Not Only Startup
This issue usually shows up during pod termination rather than at startup. A pod may look healthy for days and only reveal the problem when Kubernetes tries to stop it.
A useful test is:
- deploy the pod
- delete the pod
- watch how quickly the main process exits
- check whether child processes are left behind or termination hangs until forced
If the pod handles termination cleanly without an init shim, you may not need extra machinery.
What Else Helps In Kubernetes
An init process is only part of graceful shutdown. Also consider:
- correct
terminationGracePeriodSeconds - signal handling in the application itself
- readiness probes so traffic stops before termination
- '
preStophooks only when they solve a real lifecycle problem'
Those features complement PID 1 behavior, but they do not replace it.
Common Pitfalls
- Treating Kubernetes init containers as if they were the same thing as Docker
--init. - Assuming every container needs
tinieven when the main process already behaves correctly as PID 1. - Ignoring signal handling in the application and expecting an init shim to fix all shutdown problems.
- Adding lifecycle hooks without testing how termination actually behaves.
- Forgetting that zombie reaping matters mostly when the main process spawns child processes.
Summary
- Kubernetes has no direct Pod spec equivalent to Docker
--init. - Init containers are not the same feature; they run before the main container and then exit.
- If you need
--initbehavior, run a tiny init process such astinias PID 1 inside the container. - Some applications do not need this if they already behave correctly as PID 1.
- Test pod shutdown behavior before deciding whether an init shim is necessary.

