title: Can't connect to remote debug server with pydevd-pycharm
body: <p>I have a Django project that I deploy with docker. I want to debug the project with <code>Python Remote Debug</code>. This I how I configured it according to the <a href="https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html" rel="nofollow noreferrer">https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html</a></p>
  
  <p><a href="https://i.stack.imgur.com/2EESN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2EESN.png" alt="enter image description here"></a></p>
  
  <p>Afterwards I launched the debugger and it said:</p>
  
  <pre><code>Use the following code to connect to the debugger:
  import pydevd_pycharm
  pydevd_pycharm.settrace('0.0.0.0', port=3000, stdoutToServer=True, stderrToServer=True)
  Waiting for process connection...
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/EkxQd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EkxQd.png" alt="enter image description here"></a></p>
  
  <p>Afterwards I coppied the code to <code>__main__</code> in <code>manage.py</code></p>
  
  <p><a href="https://i.stack.imgur.com/poga7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/poga7.png" alt="enter image description here"></a></p>
  
  <p>Btw. Puting above code to some <code>views</code> instead manage.py dint help either</p>
  
  <p>Next I launched by docker with <code>docker-compose up -d proj</code> command</p>
  
  <p>After a while I saw logs from my container that says that:</p>
  
  <pre><code>Could not connect to localhost: 3000
  NoneType: None
  Traceback (most recent call last):
    File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 137, in run
      self.result = application(self.environ, self.start_response)
    File "/usr/local/lib/python3.6/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
      return self.application(environ, start_response)
    File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 93, in sentry_patched_wsgi_handler
      environ, start_response
    File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/wsgi.py", line 69, in __call__
      rv = self.app(environ, start_response)
    File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 92, in &lt;lambda&gt;
      return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 112, in sentry_patched_get_response
      return old_get_response(self, request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in get_response
      response = self._middleware_chain(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/app/xwing/middleware.py", line 21, in middleware
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
      return view_func(*args, **kwargs)
    File "/usr/local/lib/python3.6/site-packages/rest_framework/viewsets.py", line 116, in view
      return self.dispatch(request, *args, **kwargs)
    File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 492, in dispatch
      response = handler(request, *args, **kwargs)
    File "/app/cards/views.py", line 52, in version
      return Response({'version': get_newest_version()})
    File "/app/cards/queries.py", line 76, in get_newest_version
      pydevd_pycharm.settrace('localhost', port=8080, stdoutToServer=True, stderrToServer=True)
    File "/usr/local/lib/python3.6/site-packages/pydevd.py", line 1282, in settrace
      stop_at_frame,
    File "/usr/local/lib/python3.6/site-packages/pydevd.py", line 1327, in _locked_settrace
      debugger.connect(host, port)  # Note: connect can raise error.
    File "/usr/local/lib/python3.6/site-packages/pydevd.py", line 364, in connect
      s = start_client(host, port)
    File "/usr/local/lib/python3.6/site-packages/_pydevd_bundle/pydevd_comm.py", line 568, in start_client
      sys.exit(1) #TODO: is it safe?
  SystemExit: 1
  </code></pre>
  
  <p>So far I tried to run the debug server on differet ports like 0.0.0.0:8000, localhost:8000. But It didn't help. I took another project does does require docker to work, and everything worked find. It seems that there is some problem with a docker. Any ideas? I have no idea why I does not work. </p>