Ask Your Question
1

Unable to connect debugger to a docker container

asked 2020-03-22 08:42:22 -0500

martinako gravatar image

updated 2020-03-23 09:02:02 -0500

I'm following the example in here to connect the WingIDE debugger to a python script running in a docker container. However, there is some connection problem.

I've enabled kLogVeryVerbose and set kLogFile = "<stdout>" to try to diagnose the problem. I run the example with this line:

docker run -v /usr/lib/wingpro7:/wingpro7 -v /home/martin/develop/docker_tests/docker:/app -p 4000:80  myapp

and I think it stays waiting for connection until it times out.

In an attempt to troubleshot the problem I've added the container's ip address, the hosts address and the localhosts to Allowed Hosts, also same addresses both with port 50005 and 50015 to Common atttach hosts, but it doesn't seem to make any difference.

These are the logging messages I get in the console:

Creating meta importer for domain dbg
winghome=/wingpro7Created meta importer
  Added dir /wingpro7/bootstrap for
  Added dir /wingpro7/bootstrap/__pycache__ for __pycache__.
Adding code directory to merge importer: /wingpro7/bin/dbg/src
  Added dir /wingpro7/bin/dbg/src for
  Added dir /wingpro7/bin/dbg/src/__pycache__ for __pycache__.
  Added dir /wingpro7/bin/dbg/src/debug for debug.
  Added dir /wingpro7/bin/dbg/src/debug/tserver for debug.tserver.
  Added dir /wingpro7/bin/dbg/src/debug/tserver/__os__ for debug.tserver.__os__.
  Added dir /wingpro7/bin/dbg/src/debug/tserver/__os__/win32 for debug.tserver.__os__.win32.
  Added dir /wingpro7/bin/dbg/src/debug/tserver/__os__/osx for debug.tserver.__os__.osx.
  Added dir /wingpro7/bin/dbg/src/wingbase for wingbase.
  Added dir /wingpro7/bin/dbg/src/wingbase/__os__ for wingbase.__os__.
  Added dir /wingpro7/bin/dbg/src/wingbase/__os__/win32 for wingbase.__os__.win32.
  Added dir /wingpro7/bin/dbg/src/wingbase/__os__/osx for wingbase.__os__.osx.
  Added dir /wingpro7/bin/dbg/src/wingbase/__pycache__ for wingbase.__pycache__.
  Added dir /wingpro7/bin/dbg/src/wingbase/pexpect for wingbase.pexpect.
  Added dir /wingpro7/bin/dbg/src/wingbase/pexpect/ptyprocess for wingbase.pexpect.ptyprocess.
  Added dir /wingpro7/bin/dbg/src/debug/tserver/__os__/linux-x64 for debug.tserver.
  Added dir /wingpro7/bin/dbg/src/wingbase/__os__/linux-x64 for wingbase.
Adding code directory to merge importer: /wingpro7/src
  Added dir /wingpro7/src for
  Added dir /wingpro7/src/testing for testing.
  Added dir /wingpro7/src/testing/runners for testing.runners.
  Added dir /wingpro7/src/wingutils for wingutils.
  Added dir /wingpro7/src/debug for debug.
  Added dir /wingpro7/src/debug/tserver for debug.tserver.
  Added dir /wingpro7/src/debug/tserver/__pycache__ for debug.tserver.__pycache__.
  Added dir /wingpro7/src/debug/__pycache__ for debug.__pycache__.
  Added dir /wingpro7/src/debug/client for debug.client.
  Added dir /wingpro7/src/external for external.
  Added dir /wingpro7/src/external/pygments for external.pygments.
  Added dir /wingpro7/src/external/pygments/pygments for external.pygments.pygments.
  Added dir /wingpro7/src/external/pygments/pygments/formatters for external.pygments.pygments.formatters.
  Added dir /wingpro7/src/external/pygments/pygments/lexers for external.pygments.pygments.lexers.
  Added dir /wingpro7/src/external/pygments/pygments/filters for external.pygments.pygments.filters.
  Added dir /wingpro7 ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-03-27 12:33:43 -0500

martinako gravatar image

I've managed to attach the wingide debugger to the script running in the container. However, I'm not sure of the necessary steps to reproduce it and probably many of the things I tried are not necessary:

So initially I was getting the Value = [Errno 110] Connection timed out

In another terminal I run a bash in the same container where the example was running and tried to ping my host and ssh my host and I could do both from inside the container. Then I find out what the container ip adrress was from within the container and add it to the "Allowed Hosts" and "Common Attach Hosts" in wingide preferences. I also played with enabling and disabling the port 50005 in host machine with ufw, but I think this is not necessary.

At some point I started to get a different error 'Value = [Errno 111] Connection refused'

Then I added -p 50005:50005 to the docker run command and I started to get a different error Value = [Errno 104] Connection reset by peer'

Then after repeating the same run command a few time I got the error Error starting userland proxy: listen tcp 0.0.0.0:50005: bind: address already in use.

I removed the -p 50005:50005 . Then I saw the debug icon in the bottom left of wingide to turn green but still get the Value = [Errno 104] Connection reset by peer' I added a Location Map for the /app corresponding folder in my host. Then the debugger could attach to the script but not the callback function hello()

in the terminal it keep complaining that:

No valid wingdebugpw file found in the following directories: ['/wingide6', '$<winguserprofile>']

I copied wingdebugpw to /usr/lib/wingide6 and finally the breakpoints worked both in the body and the callback function.

edit flag offensive delete link more

Comments

Glad you got working! I think pretty much everything in the above wasn't needed except (a) using the right IP address, an (b) copying in wingdebugpw. Even (b) should not be needed if you are using the latest Wing because it should generate a security token automatically and the IDE should prompt you to accept it. If you are using 7.2.1.2 and it didn't do that, please let me know. BTW, when adding -p 50005:50005, which is not needed, you probably ended up conflicting w/ Wing's attempts to listen on that port and may also have had multiple active container instances (you can see this with 'docker ps' and kill the unwanted ones with 'docker kill').

Wingware Support gravatar imageWingware Support ( 2020-03-27 14:01:42 -0500 )edit
0

answered 2020-03-22 09:49:02 -0500

I wonder if kHostPort should be set as follows instead?

kWingHostPort = 'host.docker.internal:50005'

(The How-To you liked incorrectly omits the ':50005' part)

This name should work with Docker 18.03 and later, at least in the standard Python docker image. RIght now it looks like you have this set to 192.168.1.80:50005 which maybe is not right... it's confusing which IP/name to use in some Docker versions/variants and seeing that it's timing out may mean that it's not the right IP or the connection is not being routed properly.

Also check that Wing is listening for the debug connection by hovering the mouse over the bug icon in the lower left of Wing's Window.

Finally, don't set kLogVeryVerhose because it can produce 100's of MBs of output very quickly, hugely slow things down, and won't help with diagnosing connection problems anyway.

Please let us know if that doesn't help, along with what Docker version you are using and which image, and we can look further into it.

edit flag offensive delete link more

Comments

BTW, we're working on easier-to-use container support that doesn't require being able to SSH into the container, but this isn't ready yet. We're hoping to get something out through the early access program in a few weeks.

Wingware Support gravatar imageWingware Support ( 2020-03-22 09:50:10 -0500 )edit

I had already tried kWingHostPort = 'host.docker.internal:50005' before posting. I've tried again and the logging is finished with the same raise ValueError('Not connected') exception. I had Accept Debug Connections enabled. I'll update the question with the info I get from docker version.

martinako gravatar imagemartinako ( 2020-03-23 05:44:03 -0500 )edit

Given that you have CE the host.docker.internal:50005 should be the right form. The important exception is the earlier "Value = [Errno 110] Connection timed out". It's failing to connect to the IDE but I've not seen "connection timed out" before so am not certain why this is happening. Usually it just entirely fails, but it seems like it is actually connecting to somewhere at the TCP level but perhaps not Wing. One idea is to try a different port than 50005, which you can do by changing both kWingHostPort and also setting the Debugger > Listening > Server Port preference in Wing. You may also want to restart Wing and kill any still-running instances of your container with 'docker ps' and 'docker kill'. It doesn't seem like anti-virus software since that usually would just block it entirely, but maybe also worth looking into.

Wingware Support gravatar imageWingware Support ( 2020-03-23 08:14:50 -0500 )edit

Also, what Docker container are you using? The default Python container or something else? And what is the host OS and version? I'd like to try it here just to see if I can replicate the problem.

Wingware Support gravatar imageWingware Support ( 2020-03-23 08:15:32 -0500 )edit

When I use host.docker.internal:50005 it just fails to connect, it doesn't time out. I'll update the question with the log. The docker container I'm using is the one in the example Dockerfile, based on python:3.7.

martinako gravatar imagemartinako ( 2020-03-23 08:52:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-03-22 08:42:22 -0500

Seen: 39 times

Last updated: 18 hours ago