繁体   English   中英

在 Docker 容器上进行远程调试时,无法使用 Visual Studio 代码在任何断点处中断

[英]Can't break on any breakpoint with Visual Studio code while remote debugging on Docker container

我正在尝试使用 Visual Studio Code 在 Docker 容器中远程调试 Ruby(on Rails) 代码。

我的机器上没有安装 Ruby,只是在 Docker 中。


  • VSCode:1.32.3
  • 操作系统:Windows 10 专业版,1709
  • Docker 桌面:2.1.0.5 社区稳定
  • 码头工人:19.03.5
  • 红宝石:2.6.5

程序如下:

  1. Docker 容器执行命令bundle exec rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails s -b 0.0.0.0然后“Fast Debugger (ruby-debug-ide 0.7.0. beta7, debase 0.2.3.beta3, 支持文件过滤) 监听 0.0.0.0:1234"
  2. 我开始在 VScode 中调试,然后 Puma 启动。
  3. 我操作应用程序。
  4. 断点不起作用。

但是,VSCode 会在我暂停调试时指示正在执行的行。 之后我可以跨过去,变量,手表和调用堆栈正在工作。

似乎只有 BREAKPOINTS 不起作用。


这是我的文件(片段):

启动.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for rdebug-ide",
      "type": "Ruby",
      "request": "attach",
      "cwd": "${workspaceRoot},
      "remoteHost": "10.0.75.1",
      "remotePort": "1234",
      "remoteWorkspaceRoot": "/var/work/app",
      "showDebuggerOutput": true,
    }
  ]
}

docker-compose.yml:

services:
  app:
    build: "./app"
    depends_on:
      - db
    ports:
      - "3000:3000"
      - "1234:1234"
      - "26162:26162"
    volumes:
      - "./app:/var/work"
    stdin_open: true
    tty: true

Gemfile.lock:

ruby-debug-ide (0.7.0)
debase (0.2.4.1)

我的问题已经解决了。

我修改了launch.json并且它起作用了。 似乎错误的是“cmd”的目录规范。
“cmd”必须以 Windows 格式设置。

供参考,目录结构如下:

product_root
├── .vscode
│   └── launch.json
├── product
│   ├── rails_root
│   │   ├── app
│   │   ├── Gemfile
│   │   ├── etc.
│   └── Dockerfile
└── docker-compose.yml

启动文件

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for rdebug-ide",
      "type": "Ruby",
      "request": "attach",
      "cwd": "${workspaceRoot}\\product\\rails_root",
      "remoteHost": "localhost",
      "remotePort": "1234",
      "remoteWorkspaceRoot": "/var/work/rails_root"
    }
  ]
}

docker-compose.yml

services:
  app:
    build: "./product"
    depends_on:
      - db
    ports:
      - "3000:3000"
      - "1234:1234"
      - "26162:26162"
    volumes:
      - "./product:/var/work"
    stdin_open: true
    tty: true

在您的launch.json您可能需要添加 bundle 和 RdebugIde 的路径。 就像是:

{
        "name": "Debug Rails server",
        "type": "Ruby",
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "useBundler": true,
        "pathToBundler": "/path/to/rubygem/wrappers/bundle",
        "pathToRDebugIDE": "/path/to/rubygem/gems/ruby-debug-ide-x.x.x/bin/rdebug-ide",
        "program": "${workspaceRoot}/bin/rails",
        "args": [
            "server",
            "-p",
            "3000"
        ]
    }

并调试一个规范:

{
        "name": "Debug RSpec - open spec file",
        "type": "launch",
        "request": "attach",
        "cwd": "${workspaceRoot}",
        "useBundler": true,
        "pathToBundler": "/path/to/rubygem/wrappers/bundle",
        "pathToRDebugIDE": "/path/to/rubygem/gems/ruby-debug-ide-x.x.x/bin/rdebug-ide",
        "debuggerPort": "1235",
        "program": "/path/to/rubygem/bin/rspec",
        "args": [
            "${file}"
        ]
    }

请参考: https : //github.com/Microsoft/vscode-recipes/tree/master/debugging-Ruby-on-Rails#bonus了解更多信息。

这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM