0

Summary

I'm on mac. I have several docker containers, I can run all of them using docker-compose up and everything works as expected: for instance, I can access my backend container by searching http://localhost:8882/ on my browser, since port 8882 is mapped to the same port on host by using:

ports:
  - "8882:8882"

Problems start when I try to attach an IDE to the backend container so as to be able to develop "from inside" that container.

I've tried using vscode's plugin "Remote - Containers" following this tutorial and also pycharm professional, which comes with the possibility to run docker configurations out of the box. On both cases I had the same result: I run the IDE configuration to attach to the container and its local website suddenly stops working, showing "this site can't be reached".

When using pycharm, I noticed that Docker Desktop shows that the backend container changed its port to 54762. But I also tried that port with no luck.

I also used this command:

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

to get the container ip (172.18.0.4) and tried that with both ports, again, same result.

Any ideas?

Pycharm configuration

Interpreter: enter image description here

This works in the sense that I can watch the libraries code installed inside the container:

enter image description here

Run/Debug configuration. This configuration succeeds in the sense that I can start it and it seems to be attached correctly to the backend container... though the problem previously described appears.

enter image description here

Alvaro Rodriguez Scelza
  • 3,643
  • 2
  • 32
  • 47

1 Answers1

0

So, there were many things taking part in this, since this is an already huge and full of technical debt project.

But the main one is that the docker-compose I was using was running the server using uwsgi on production mode, which tampered many things... amongst which were pycharm's ability to successfully attach to the running container, debug, etc.

I was eventually able to create a new docker-compose.dev.yml file that overrided the main docker-compose file, only to change the backend server command for flask on development mode. That fixed everything.

Be mindful that for some reason flask run command inside a docker container does not allow you to see the website properly until you pass a -host=0.0.0.0 option to it. More in https://stackoverflow.com/a/30329547/5750078

Alvaro Rodriguez Scelza
  • 3,643
  • 2
  • 32
  • 47