Debug nodejs app when it runs inside Docker container #1201
Replies: 3 comments 1 reply
-
So reading carefully the guidelines again it seems that the adapter needs to run inside the docker container, so I managed to install manually from the official repository, and now I can run it inside the container. However here is another hurdle, how can I tell nvim-dap that the debugger is running inside the container? Currently this is my nvim-dap config for the adapter:
As you can see I'm not using the executable key to run the adapter and that is because for some reason nvim-dap never calls the command I set so I'm my case I have to start the adapter manually in a separated terminal and it always the assigned port is always 8123, other than that all works just fine for debugging locally. Now both the debugger (the one called with the node --inspect flag) and the adapter are running inside the docker container, all the relevant ports are exposed in the Dockerfile and mapped to localhost when I run the container:
But when I start a debugging session and choose the configuration for docker (the one I shared in the OP) I get immediately a ECONNRESET error and then:
My log level is ERROR and when I check the Any ideas of what can I do to tell nvim-dap to connect the adapter to the debugger when they are running inside the container? |
Beta Was this translation helpful? Give feedback.
-
I think I make a little bit of advance. I added the launch.json
tasks.json
I have to run the command in detach mode otherwise nvim-dap gives me:
Which is weird because if I inspect the process inside the container with the
Also I can attach successfully to the process with Also I don't get any output in the dap.log file. This changes if I run the command in detach mode However now when I inspect the dap.log file I can finally see a couple of logs:
So at least now nvim-dap is actually sending the message to the adapter to try to communicate with it, unfortunately there is no response from it. Note: I'm 'hardcoding' the port to connect to the adapter just for now as every time I inspect the process with Again this was a little advance but now I can double confirm that my issue is that nvim-dap cannot connect to the adapter, it is sending the message but there is no response. And well here tbh I don't have any clue about how to continue but at the same time I think that if I manage to solve this issue the remaining parts will be much easier. |
Beta Was this translation helpful? Give feedback.
-
I implemented process id selection, just to be sure that I was getting the right process, for this I had to find a way to get into the container processes which I did thanks to reading this PR, now when nvim-dap sends the 'initialize' message to the adapter it also sends the process id for the adapter in the message:
However this didn't solve the issue, the adapter still is not responding, which led me to think that the problem could be actually the adapter (I know maybe I should've think on this at the beginning), so I tried a simple GET request to the adapter, this is the result when I do that inside the running container:
And the server hangs, which means there is no actual response from the adapter, but the connection is being establish. Now if I make the request from localhost (outside the container) I get the very same result as above but with these extra lines:
And just to be sure that the adapter is actually running I manually started the adapter in a separate terminal and it ran just fine with the usual message and no errors, then I repeat the curl requests both from inside the container and from outside, and get the same output that I just showed.
So to summarize, the connection to the server is being establish without errors but it is not responding. |
Beta Was this translation helpful? Give feedback.
-
I managed to set nvim-dap to debug nodejs apps using dapDebugServer.js, now I would like to go one step further and debug nodejs apps when they are running inside a docker container.
I've read the guidelines but still I can't make it work.
Just to compare this is the launch.json of my project which contain first the local debugging config (which works perfectly) and then a copy of the former with modifications I introduced according to what I was reading on internet about the subject.
Note: Port 4001 is the port I manually assigned to the node --inspect flag and it is exposed at the end of my Dockerfile
These are the relevant parts of the command I use to run the container.
When I try to start a new debug session with the second configuration (the one for Docker) I get this error:
And when I look at the nodejs debugger adapter logs I can see:
What I'm missing here?
Beta Was this translation helpful? Give feedback.
All reactions