title: Debugging python in docker container using debugpy and vs code results in timeout/connection refused
body: <p>I'm trying to setup native debugging for a python script running in docker for Visual Studio Code using debugpy.  Ideally I'd like to just F5 and be on my way (including a build phase if needed).  Currently I'm bouncing between a timeout caused from <code>debugpy.listen(5678)</code> inlined within the VS code editor itself (Exception has occurred: RuntimeError timed out waiting for adapter to connect) or a connection refused.</p>
  <p>I created a launch.json from the documentation provided by microsoft:</p>
  <h3>launch.json</h3>
  <pre><code>{
      &quot;version&quot;: &quot;0.2.0&quot;,
      &quot;configurations&quot;: [
          {
              &quot;name&quot;: &quot;Attach to Integration (test)&quot;,
              &quot;type&quot;: &quot;python&quot;,
              &quot;request&quot;: &quot;attach&quot;,
              &quot;pathMappings&quot;: [
                  {
                      &quot;localRoot&quot;: &quot;${workspaceFolder}/test&quot;,
                      &quot;remoteRoot&quot;: &quot;/test&quot;
                  }
              ],
              &quot;port&quot;: 5678,
              &quot;host&quot;: &quot;127.0.0.1&quot;
          }
      ]
  }
  </code></pre>
  <p>building the image looks like this so far:</p>
  <h3>Dockerfile</h3>
  <pre><code>FROM python:3.7-slim-buster as base
  RUN apt-get -y update; apt-get install -y vim git cmake
  
  WORKDIR /
  RUN mkdir .cache src in out config log
  COPY requirements.txt .
  RUN pip install -r requirements.txt; rm requirements.txt
  
  #! TODO: config folder needs to be a mapped volume so they can change creds without rebuild
  WORKDIR /src
  COPY test   ../test
  COPY config ../config
  COPY src/   .
  
  #?   D E B U G   I M A G E
  FROM base as debug
  RUN pip install debugpy
  CMD python -m debugpy --listen 0.0.0.0:5678 ../test/edu.employer._test.py
  
  #!   P R O D U C T I O N   I M A G E
  # FROM base as prod
  # CMD [ &quot;python&quot;, &quot;/test/edu.employer._test.py&quot; ]
  </code></pre>
  <p>Some examples I found try to simply things with a docker-compose.yaml, but I'm unsure if i need one at this point.</p>
  <h3>docker-compose.yaml</h3>
  <pre><code>services:
      tester:
          container_name: tester
          image: employer/test:1.0.0
          build:
              context: .
              target: debug
              dockerfile: test/edu.employer._test.Dockerfile
  
          volumes:
              - ./out:/out
              - ./.cache:/.cache
              - ./log:/log
  
          ports:
              - 5678:5678
  </code></pre>
  <p>which I based off a the CLI command: <code>docker run -it -v $(pwd)/out:/out -v $(pwd)/.cache:/.cache -v $(pwd)/log:/log employer/test:1.0.0;</code></p>
  <p>&quot;critical&quot; parts of my script just listen and wait for the bugger:</p>
  <pre><code>from __future__ import absolute_import
  
  # Standard
  import os
  import sys
  
  # 3rd Party
  import debugpy
  debugpy.listen(5678)
  debugpy.wait_for_client()
  
  # 1st Party.  NOTE: All source files are in /src, so we can add that path here for testing
  # and batch import all integrations files.  Not very clean however
  sys.path.insert(0, os.path.join('/', 'src'))
  import integrations as ints
  </code></pre>
  <p><a href="https://i.stack.imgur.com/I8EeU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/I8EeU.png" alt="screenshot" /></a></p>