如何使用 docker-compose.debug.yml 调试 docker 中的节点 运行?
How do I use docker-compose.debug.yml to debug my node running in docker?
我已经使用 vs docker extension 创建了 docker 个文件。但我不知道使用 docker-compose.debug.yml 调试代码的 "proper" 方法是什么,例如我该如何设置我的环境。这样我就可以按 F5 键,所有的魔法都会发生。
我确实找到了调试代码的方法。终端中的第一个 运行 docker-compose -f docker-compose.debug.yml
。然后使用 In-container Node Development: Visual Studio Code 中的 launch.json 附加到我在 docker 中的节点。
但我认为代码可能会提供一种更简单的方法来简化调试过程。
您可以做到这一点,但需要进行一些修改。
launch.json
{
// 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"
// }
]
}
如您所见,我对本地发布进行了评论,并将其设为第一个,因此它在 F5 上 运行。接下来我们需要定义一个start_node_compose
任务
tasks.json
{
"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"
]
}
]
}
然后当你运行使用F5命令时你将能够命中断点
我遇到了同样的问题。使用 --inspect=0.0.0.0:9229
解决了它。
我建议您也使用 --inspect-brk
,让节点进程等待调试器附加。
我已经使用 vs docker extension 创建了 docker 个文件。但我不知道使用 docker-compose.debug.yml 调试代码的 "proper" 方法是什么,例如我该如何设置我的环境。这样我就可以按 F5 键,所有的魔法都会发生。
我确实找到了调试代码的方法。终端中的第一个 运行 docker-compose -f docker-compose.debug.yml
。然后使用 In-container Node Development: Visual Studio Code 中的 launch.json 附加到我在 docker 中的节点。
但我认为代码可能会提供一种更简单的方法来简化调试过程。
您可以做到这一点,但需要进行一些修改。
launch.json
{
// 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"
// }
]
}
如您所见,我对本地发布进行了评论,并将其设为第一个,因此它在 F5 上 运行。接下来我们需要定义一个start_node_compose
任务
tasks.json
{
"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"
]
}
]
}
然后当你运行使用F5命令时你将能够命中断点
我遇到了同样的问题。使用 --inspect=0.0.0.0:9229
解决了它。
我建议您也使用 --inspect-brk
,让节点进程等待调试器附加。