如何使用docker-compose.debug.yml调试在docker中运行的节点? [英] How do I use docker-compose.debug.yml to debug my node running in docker?

查看:451
本文介绍了如何使用docker-compose.debug.yml调试在docker中运行的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用


I have used vs docker extension to create docker files. But I don't know what is the "proper" way to use docker-compose.debug.yml to debug my code, e.g. how do I set my env. so I can just hit F5 and all the magic happen.

I did work out a way to debug my code. First run docker-compose -f docker-compose.debug.yml in terminal. Then use the launch.json from In-container Node Development: Visual Studio Code to attach to my node in docker.

But I think Code may provide a simpler way to streamline the debug process.

解决方案

You can do that but through some modifications.

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"
        // }
    ]
}

As you can see I commented the local launch and made this the first one so it is run on F5. Next we need to define a start_node_compose task

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"
            ]
        }
    ]
}

Then when you run the command using F5 you will be able to hit the breakpoint

这篇关于如何使用docker-compose.debug.yml调试在docker中运行的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆