title: Debugging nestjs application with --watch from vscode with docker stops on changed file
body: <p>I am trying to debug a typescript nestjs application in <code>--watch</code> mode (so it restarts when files are changed) in Visual Studio code (using the Docker extension). The code is mounted in docker through the use of a volume.</p>
  <p>It almost works perfectly, the docker is correctly launched, the debugger can attach, however I have one problem that I can't seem to work out:</p>
  <p>As soon as a file is changed, the watcher picks it up and I see the following in <code>docker logs -f</code> for the container:</p>
  <pre><code>[...]
  [10:12:59 AM] File change detected. Starting incremental compilation...
  
  [10:12:59 AM] Found 0 errors. Watching for file changes.
  
  Debugger listening on ws://0.0.0.0:9229/af60f5e3-394d-4df3-a565-8d15898348bf
  For help, see: https://nodejs.org/en/docs/inspector
  user@system:~$
  # (at this point the docker logs command stops and the docker is gone)
  </code></pre>
  <p>At that point vscode ends the debugging session, the docker stops (or vice versa?) and I have to manually restart it.</p>
  <p>If I launch the exact same docker command (copy/pasted from the vscode terminal window) manually, it does not stop when changing a file. This is the command it generates:</p>
  <pre><code>docker run -dt --name &quot;core-dev&quot; -e &quot;DEBUG=*&quot; -e &quot;NODE_ENV=development&quot; --label &quot;com.microsoft.created-by=visual-studio-code&quot; -v &quot;/home/user/projects/core:/usr/src/app&quot; -p &quot;4000:4000&quot; -p &quot;9229:9229&quot; --workdir=/usr/src/app &quot;node:14-buster&quot; yarn run start:dev --debug 0.0.0.0:9229
  </code></pre>
  <p>I did try to look with strace what happens and this is what I see on the node process when I change any file:</p>
  <pre><code>strace: Process 28315 attached
  --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=40, si_uid=0, si_status=SIGTERM, si_utime=79, si_stime=9} ---
  +++ killed by SIGKILL +++
  </code></pre>
  <p>The <code>killed by SIGKILL</code> line does <strong>not</strong> happen when docker is run manually, it only happens when it's started from vscode when debugging.</p>
  <p>Hopefully someone has an idea where I'm going wrong.</p>
  <p>Here are the relevant configs:</p>
  <p><strong>launch.json</strong></p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;version&quot;: &quot;0.2.0&quot;,
      &quot;configurations&quot;: [
          {
              &quot;name&quot;: &quot;Docker Node.js Launch&quot;,
              &quot;type&quot;: &quot;docker&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;preLaunchTask&quot;: &quot;docker-run: debug&quot;,
              &quot;platform&quot;: &quot;node&quot;
          }
      ]
  }
  </code></pre>
  <p><strong>tasks.json</strong></p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;version&quot;: &quot;2.0.0&quot;,
      &quot;tasks&quot;: [
          {
              &quot;type&quot;: &quot;docker-run&quot;,
              &quot;label&quot;: &quot;docker-run: debug&quot;,
              &quot;dockerRun&quot;: {
                  &quot;customOptions&quot;: &quot;--workdir=/usr/src/app&quot;,
                  &quot;image&quot;: &quot;node:14-buster&quot;,
                  &quot;command&quot;: &quot;yarn run start:dev --debug 0.0.0.0:9229&quot;,
                  &quot;ports&quot;: [{
                      &quot;hostPort&quot;: 4000,
                      &quot;containerPort&quot;: 4000
                  }],
                  &quot;volumes&quot;: [
                      {
                          &quot;localPath&quot;: &quot;${workspaceFolder}&quot;,
                          &quot;containerPath&quot;: &quot;/usr/src/app&quot;
                      }
                  ],
                  &quot;env&quot;: {
                      &quot;DEBUG&quot;: &quot;*&quot;,
                      &quot;NODE_ENV&quot;: &quot;development&quot;
                  }
              },
              &quot;node&quot;: {
                  &quot;enableDebugging&quot;: true,
              }
          }
      ]
  }
  </code></pre>
  <p>Here is a hello world repo: <a href="https://github.com/strikernl/nestjs-docker-hello-world" rel="nofollow noreferrer">https://github.com/strikernl/nestjs-docker-hello-world</a></p>