Pycharm + docker-compose, django server is not responding!

Answered

Everything runs fine, breakpoints run, debugger is connected, the runserver command runs properly and the server is started.

 

Whenever I send a request to that server though, there is server not found!

 

 

Recreating django_server ... 
Attaching to django_server
django_server | pydev debugger: starting
django_server |
Connected to pydev debugger (build 183.5429.31)
django_server | pydev debugger: New process is launching (breakpoints won't work in the new process).
django_server | pydev debugger: To debug that process please enable 'Attach to subprocess automatically while debugging?' option in the debugger settings.
django_server |
django_server | Performing system checks...
django_server |
django_server | System check identified no issues (0 silenced).
django_server | February 03, 2019 - 08:52:09
django_server | Django version 2.1.5, using settings 'config.settings'
django_server | Starting development server at http://0.0.0.0:8032/
django_server | Quit the server with CONTROL-C.

docker ps:

CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                                                         NAMES

34f7bd877cec        django_server           "python -u /opt/.pyc…"   5 minutes ago       Up 5 minutes        0.0.0.0:51150->51150/tcp, 52291/tcp, 0.0.0.0:8032->8000/tcp   django_server

 

The container has the open ports and everything should be fine, but it doesn't respond to any requests! When I run the docker-compose myself, it works well but no debugging offcourse!

14 comments
Comment actions Permalink

Hi,

Please elaborate on what do you mean by "server not found" ?

You're not getting a response on HTTP request? Is the execution paused on any breakpoint in that moment?

0
Comment actions Permalink

The request doesn't reach the server, host not found. like If I would access a server that does not exist

1
Comment actions Permalink

Please specify what kind of request are you taking about and how do you send it.

Is it working if you run the configuration without debugger from PyCharm?

0
Comment actions Permalink

Same issue here. I'm making a request from a browser to the django server running in the container. Tried both 127.0.0.1:8000 and 0.0.0.0:8000 to no avail. Both used to work in previous versions of pycharm. Mine also works if I run it from terminal with `docker-compose -f local.yml up`

0
Comment actions Permalink

@Isaac

So you are able to open http://0.0.0.0:8000/ in your browser but then you cannot make any requests?

0
Comment actions Permalink

Correct. For example, Firefox and cURL say they fail because “connection was reset”

0
Comment actions Permalink

Do you have the same problem if you start your Django server from the system terminal (outside of PyCharm) by running the same command PyCharm does?

0
Comment actions Permalink

When I run it from a terminal instead of a PyCharm run config, it connects and the site works. When using the run config, it won't connect.

0
Comment actions Permalink

Hmmm, that's odd.

There is probably something in run configuration that causing this since when you run the same command as PyCharm from the system terminal and it doesn't have this issue.

Does it work with our example from the documentation https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter.html? There is a link to a project on GitHub.

I tried to reproduce on different OS, but it works fine.

0
Comment actions Permalink

Hi same error for me, I'm using Pycharm 2019.1. When I use command line my django app works fine, but not when I use pycharm. when I check the configuration. I see that Pycharm override my docker-compose configuration. If I check this config I see 

 

services:
web:
command:
- "/usr/bin/python3"
- "-u"
- "/opt/project/manage.py"
- "runserver"
- "8000"
environment:
PYTHONPATH: "/opt/project:/opt/.pycharm_helpers/pycharm_matplotlib_backend:/opt/.pycharm_helpers/pycharm_display"
DJANGO_SETTINGS_MODULE: "five_backend.settings.local"
PYTHONUNBUFFERED: "1"
PYTHONIOENCODING: "UTF-8"
PYCHARM_HOSTED: "1"
PYCHARM_DISPLAY_PORT: "62101"
stdin_open: true
volumes:
- "/Users/yavin4/dev/five-backend:/opt/project:rw"
- "pycharm_helpers_PY-191.6183.50:/opt/.pycharm_helpers"
working_dir: "/opt/project"
volumes:
pycharm_helpers_PY-191.6183.50: {}

 

the port 8000 is not shared. between the host and the container. and I cannot override this config. 

0
Comment actions Permalink

PyCharm just adds its own configuration file with needed settings, it doesn't overwrite your config(s).

Does it work with our example from the documentation https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter.html? There is a link to a project on GitHub.

0
Comment actions Permalink

I had the same problem, using the default Django Server run configuration with the Docker Compose interpreter selected.

It turns out that you must specify 0.0.0.0 in the "Host" field of the server run configuration. (This field is blank by default.) Once that is specified, and the server restarted if necessary, you will be able to access the server running in the Docker container at 127.0.0.0:8000 (assuming you're using the default 8000 port).

4
Comment actions Permalink

If you are using Django, it's important to add:

runserver 0.0.0.0:8000

in Parameters field of Run/Debug configuration dialog.

1
Comment actions Permalink

If Anyone came here from Following this Guide: https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter.html?_ga=2.251633153.645674516.1589467895-593042553.1588614408

 

At the Time of Writing I am Using

PyCharm 2020.1.1 (Professional Edition)
Build #PY-201.7223.92, built on April 30, 2020

Runtime version: 11.0.6+8-b765.40 amd64

VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Linux 5.3.0-46-generic
GC: ParNew, ConcurrentMarkSweep
Non-Bundled Plugins: com.chrisrm.idea.MaterialThemeUI, com.mallowigi
Current Desktop: ubuntu:GNOME

 

 

I had struggled with an issue to set this up on a project that wasn't owned by me. The example they give is if you have the internal docker port matching the external.

 

In order to have this work with a different internal port, for example

 

 

FROM python:3.6.7

WORKDIR /app

# By copying over requirements first, we make sure that Docker will cache
# our installed requirements rather than reinstall them on every build
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

# Now copy in our code, and run it
COPY . /app
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:5000"]

 

Notice the 5000

 

version: '3'
services:
web:
build: .
ports:
- "8000:5000"
volumes:
- .:/app
links:
- db

db:
image: "postgres:9.6"
ports:
- "8432:5432"
environment:
POSTGRES_PASSWORD: hunter2

 

Notice

ports:
- "8000:5000"

 

 

 

 

If you are requiring any help you can reach me at here

0

Please sign in to leave a comment.