title: Why docker exec is killing nohup process on exit?
body: <p>I have running docker ubuntu container with just a bash script inside. I want to start my application inside that container with docker exec like that:</p>
  
  <pre><code>docker exec -it 0b3fc9dd35f2 ./main.sh
  </code></pre>
  
  <p>Inside main script I want to run another application with nohup as this is a long running application:</p>
  
  <pre><code>#!/bin/bash
  nohup ./java.sh &amp;
  #with this strange sleep the script is working
  #sleep 1
  echo `date` finish main &gt;&gt; /status.log
  </code></pre>
  
  <p>The java.sh script is as follow (for simplicity it is a dummy script):</p>
  
  <pre><code>#!/bin/bash
  sleep 10
  echo `date` finish java &gt;&gt; /status.log
  </code></pre>
  
  <p>The problem is that java.sh is killed immediately after docker exec returns. The question is why?</p>
  
  <p>The only solution I found out is to add some dummy <code>sleep 1</code> into the first script after nohup is started. Than second process is running fine. Do you have any ideas why it is like that?</p>
  
  <p>[EDIT]</p>
  
  <p>Second solution is to add some <code>echo</code> or <code>trap</code> command to <code>java.sh</code> script just before sleep. Than it works fine. Unfortunately I cannot use this workaround as instead of this script I have java process.</p>