Debug python application running in Docker
<p>I've just recently begun trying to wrap my head around Docker and have managed to get a development machine up and running. What i'm now trying to do is to be able to use the debugger in Visual Studio Code in my python application (specifically Django).</p>
<p>I've tried following the limited documentation of the <a href="https://github.com/DonJayamanne/pythonVSCode/wiki/Debugging:-Remote-Debuging" rel="nofollow noreferrer">python extension for VS Code</a> which explains the parameters for remote debugging.</p>
<h3>Dockerfile</h3>
<pre><code>FROM python:3.5.2
RUN apt-get update \
--no-install-recommends &amp;&amp; rm -rf /var/lib/apt/lists/* \
&amp;&amp; mkdir -p /code \
EXPOSE 8000
WORKDIR /code
COPY requirements.txt /code
RUN /bin/bash --login -c &quot;pip install -r requirements.txt&quot;
ADD . /code
CMD []
</code></pre>
<h3>docker-compose.yml</h3>
<pre><code>version: '2'
services:
    db:
        image: postgres
    web:
        build: .
        volumes:
            - .:/code
        ports:
            - &quot;8000:8000&quot;
        command: bash -c &quot;./wait-for-it.sh db:5432 &amp;&amp; python manage.py migrate &amp;&amp; python manage.py runserver 0.0.0.0:8000 --noreload&quot;
        depends_on:
            - db
</code></pre>
<h3>launch.json</h3>
<pre><code>{
    &quot;name&quot;: &quot;Attach (Remote Debug)&quot;,
    &quot;type&quot;: &quot;python&quot;,
    &quot;request&quot;: &quot;attach&quot;,
    &quot;localRoot&quot;: &quot;${workspaceRoot}&quot;,
    &quot;remoteRoot&quot;: &quot;/code&quot;,
    &quot;port&quot;: 8000,
    &quot;secret&quot;: &quot;debug_secret&quot;,
    &quot;host&quot;: &quot;localhost&quot;
}
</code></pre>
<p>I've also added the line <code>ptvsd.enable_attach(&quot;debug_secret&quot;, address = ('0.0.0.0', 8000))</code> to one of the project files</p>
<h3>The Issue</h3>
<p>When ever I start the debugger nothing happens and it looks like VS Code is waiting for a breakpoint to hit. But it never does.</p>
<p>Any ideas?</p>
<h3>EDIT: Minor update</h3>
<p>I have tried using different ports for the debugger aswell as exposing the new ports in <code>docker-compose.yml</code> without any success. It looks like the attach is successfull because the debugger doesn't crash but no breakpoint is triggered. I'm really stuck on this one.</p>
<h1>Solution</h1>
<p>See answer from theBarkman.
I'll add that I was unable to use a secret to get this working. I did the following:</p>
<p><strong>manage.py</strong></p>
<pre><code>import ptvsd
ptvsd.enable_attach(secret=None, address=('0.0.0.0', '3000'))
</code></pre>
<p><strong>launch.json</strong></p>
<pre><code>{
        &quot;name&quot;: &quot;Attach Vagrant&quot;,
        &quot;type&quot;: &quot;python&quot;,
        &quot;request&quot;: &quot;attach&quot;,
        &quot;localRoot&quot;: &quot;${workspaceRoot}&quot;,
        &quot;remoteRoot&quot;: &quot;/code&quot;,
        &quot;port&quot;: 3000,
        &quot;secret&quot;: &quot;&quot;,
        &quot;host&quot;:&quot;localhost&quot;
    }
</code></pre>