<p>I need a deployment where each pod has a single container and each container has 2 java processes running. Since a container starts with a process(P1), and if that particular process(P1) is killed, the pod restarts. Is it possible, that container starts with 2 processes, and even if one of them is killed, the container(or pod in our case, since each pod has only one container) restarts? I could not find any documentation related to this which says it can/cannot be done. Also, how can I start the container with 2 processes? If I try something like this (javaProcess is a java file) in my docker image, it runs only the first process :</p>
<pre><code>java -jar abc.jar
java javaProcess
or 
java javaProcess
java -jar abc.jar
</code></pre>
<p>If I start the container with one process(P1) and start the other process(P2) after the container is up, the container would not be bound to P2 and hence if P2 terminates, the container won't restart. But, I need it to restart!</p>

<p>You can do this using <a href="http://supervisord.org/" rel="nofollow noreferrer">supervisord</a>. Your main process should be bound to supervisord in docker image and two java processes should be managed using supervisord. </p>

<blockquote>
  <p>supervisord‘s primary purpose is to create and manage processes based
  on data in its configuration file. It does this by creating
  subprocesses. Each subprocess spawned by supervisor is managed for the
  entirety of its lifetime by supervisord (supervisord is the parent
  process of each process it creates). When a child dies, supervisor is
  notified of its death via the SIGCHLD signal, and it performs the
  appropriate operation.</p>
</blockquote>

<p>Following is a sample supervisord config file which start two java processes. (supervisord.conf)</p>

<pre><code>[supervisord]
nodaemon=true

[program:java1]
user=root
startsecs = 120
autorestart = true
command=java javaProcess1

[program:java2]
user=root
startsecs = 120
autorestart = true
command=java javaProcess2
</code></pre>

<p>In your docker file you should, do something like this:</p>

<pre><code>RUN apt-get update &amp;&amp; apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
</code></pre>
