Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot attach debugger to a node.js application running inside a Docker container #59

Closed
m90 opened this issue Nov 18, 2015 · 4 comments · May be fixed by GarfieldZHU/vscode#2
Closed
Assignees
Labels
feature-request Request for new features or functionality

Comments

@m90
Copy link

m90 commented Nov 18, 2015

I'm trying to attach the Visual Studio Code debugger to a node.js app that is running inside a Docker container.

The app starts like:

node --debug-brk app.js

My docker-compose.yml exposes the port for attaching:

app:
  build: .
  working_dir: /code
  volumes:
    - .:/code
  command: npm run debug
  ports:
    - "3004:3000"
    - "5858:5858"

launch.json is pretty simple:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Docker",
            "type": "node",
            "request": "attach",
            "port": 5858
        }
    ]
}

Now, when I start the application and attach the debugger this will correctly connect (I can see the values flashing in the debugger UI already), but then it will stop, telling me the following:

Error opening 'app.js' (File not found: /code/app.js).

Is there any way to fix this path offset? Should one handle this scenario completely different?

@weinand
Copy link
Contributor

weinand commented Nov 19, 2015

VS Code assumes that the (absolute) file paths returned from node.js, can be found in the filesystem where VS Code runs. As long as node.js runs on the same system as VS Code, this is always the case.
In your case node.js runs on a different system than VS Code, so the paths returned from node.js are not valid in VS Code.

We are planning to improve this path mapping soon. Until that has happened, can you try tweak your setup, so that the docker paths are valid paths on your host system too? (e.g. by using symbolic links).

@weinand weinand added the feature-request Request for new features or functionality label Nov 19, 2015
@m90
Copy link
Author

m90 commented Nov 19, 2015

Thanks for getting back to me so fast. I already tried the symlinking approach and everything mentioned in this Stack Overflow post (notice that although the question is 0.8, the issues persist) but could not get it to work in any constellation.

Should symlinking work in theory (i.e. has anyone of you ever managed to debug a node app inside a container yet)?

@weinand
Copy link
Contributor

weinand commented Nov 22, 2015

This issue was moved to microsoft/vscode-node-debug#8

@weinand weinand closed this as completed Nov 22, 2015
@ghost
Copy link

ghost commented Jul 1, 2016

This is late to the game but I just ran into this issue. Make sure your remoteRoot node and localRoot node in your launch.json point to the proper location. I have a situation where I develop in a /lib folder and in my Docker file the files are put in a /app folder. This is how my launch.json is configured...

        "localRoot": "${workspaceRoot}/lib",
        "remoteRoot": "/app/"

The debugger will attach properly then.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
miguelsolorio pushed a commit that referenced this issue Apr 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants