Qiu*_*ang 7 remote-debugging node.js docker visual-studio-code
我已经使用vs docker 扩展来创建 docker 文件。但我不知道使用 docker-compose.debug.yml 调试我的代码的“正确”方法是什么,例如我如何设置我的环境。所以我可以按 F5 并且所有的魔法都会发生。
我确实找到了一种调试代码的方法。首先docker-compose -f docker-compose.debug.yml
在终端运行。然后使用来自容器内节点开发:Visual Studio Code的 launch.json附加到我在 docker中的节点。
但我认为 Code 可能会提供一种更简单的方法来简化调试过程。
你可以做到这一点,但通过一些修改。
启动文件
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "127.0.0.1",
"port": 9229,
"localRoot": "${workspaceRoot}",
"remoteRoot": "/usr/src/app",
"preLaunchTask": "start_node_compose"
}
// {
// "type": "node",
// "request": "launch",
// "name": "Launch Program",
// "program": "${workspaceRoot}/index.js"
// }
]
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我评论了本地发布并将其设为第一个,因此它在 F5 上运行。接下来我们需要定义一个start_node_compose
任务
任务文件
{
"version": "0.1.0",
"command": "myCommand",
"isShellCommand": false,
"args": [],
"showOutput": "always",
"tasks": [
{
"taskName": "start_node_compose",
"showOutput": "always",
"isBuildCommand": true,
"command": "/bin/bash",
"args": [
"-c",
"docker-compose -f docker-compose.yml -f docker-compose.debug.yml up -d && sleep 10"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后当您使用 F5 运行命令时,您将能够命中断点
归档时间: |
|
查看次数: |
4291 次 |
最近记录: |