The developers at my team asked me to enable them remote debugging, and since I had a pleasure using is for personal use, I am trying if it will be a good fit here as well.
The requirement is to debug the code that is in the built container, deployed in our dev cluster.
The app is built using NodeJS, so we can start the debugger like so:
node --inspect=0.0.0.0:9229 ./dist/index.js
And then connect to it on VS Code using this config in launch.json
I am able to connect to the debugger but not set breaking points, what am I missing in this flow to allow this? Unfortunately the container does not support launching vs code in it (it’s built on top of Alpine)
This makes me believe that the problem is in the vscode config launch.json, since okteto only does the port forwarding in this case and you are able to connect. I had a similar issue that was solved by opening vscode in the subfolder of that particular project
Could you try using this simpler config?
{
"name": "Connect to okteto",
"type": "node",
"request": "attach",
"mode": "remote",
"remotePath": "/usr/src/app", // Review this for your container
"port": 9229,
"host": "localhost"
"skipFiles": [
"<node_internals>/**"
]
}
If that doesn’t work, try different values of localRoot and remoteRoot
mode,remotePath, and host according to my VS Code are not valid keys.
I am wondering if what I am tasked is with possible. Debug code that is not stored in the local but remotely on the container…
What do you think? Perhaps I should attach a web IDE as different container to the pod?
If so, how can that be done with Okteto?
If you want to use the debugger in your local machine to attach to code in a dev container, you need to have a copy of the code available locally (otherwise, VSCode won’t know how to debug it).
The configuration you shared is for when the process and the debugger are running on the same machine (or container).
This scenario is possible using our VS Code extension. You’d need to:
You’d need to do the following:
Install the extension
Execute the Okteto Up command on the extension (this will execute the okteto up sequence and then start a remote VS Code session
Open the source code you want to attach to on the remote VSCode instance, and start your debugger.