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

Viewed 2284

I'm trying to remote debug Ruby(on Rails) code in a Docker container with Visual Studio Code.

I do not have Ruby installed on my machine, just in Docker.


  • VSCode: 1.32.3
  • OS: Windows 10 Profesionnal, 1709
  • Docker Desktop: 2.1.0.5 Community stable
  • Docker: 19.03.5
  • Ruby: 2.6.5

The procedure is as follows:

  1. Docker container executes command bundle exec rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails s -b 0.0.0.0 then "Fast Debugger (ruby-debug-ide 0.7.0.beta7, debase 0.2.3.beta3, file filtering is supported) listens on 0.0.0.0:1234"
  2. I start debugging in VScode and Puma starts.
  3. I operate the application.
  4. Break points are not working.

However, VSCode indicates the line being executed when I pause debugging. After that I can step over and VARIABLES, WATCH and CALL STACK are working.

It seems that only BREAKPOINTS are not working.


Here is my file (snippets):

launch.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)
2 Answers

My problem has been solved.

I modified launch.json and it worked. It seems that what was wrong was the directory specification of "cmd".
"cmd" had to be set in Windows format.

For reference, the directory structure is as follows:

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

launch.json

{
  "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

In your launch.json you might need to add paths to bundle and RdebugIde. Something like:

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

and to debug one spec:

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

Please refer: https://github.com/Microsoft/vscode-recipes/tree/master/debugging-Ruby-on-Rails#bonus for more info.

This work for me.

Related