LoginSignup
1
1

RubyMineのリモートデバッガーを使ってDocker Composeで立ち上げたRailsをデバッグしたい

Posted at

RubyMineのリモートデバッガーを使ってDocker Composeで立ち上げたRailsをデバッグしたい

はじめに

Docker-composeで立ち上げたRailsをRubyMineでデバッグしたかったが、なかなか接続できずに苦労したのでその備忘録
 

環境

  • M1 Mac
  • macOS Venture 13.3.1
  • RubyMain 2023.1 Trial
  • Ruby 2.7.8
  • すでにRailsアプリがDocker-composeを実行できること

やりかた

準備

  1. Edit Configurationsにて、"Ruby remote debug"を追加
    設定はこんな感じ
    Screenshot 2023-05-28 at 13.57.28.png
    {YOUR_REMOTE_ROOT_FOLDER}と{YOUR_LOCAL_ROOT_FOLDER}は任意のパスに変更してください。

  2. GemFileにデバッグ用のGemを追加

    ~~ (略) ~~
    group :development do
    	~~ (略) ~~
    
      gem "debase", "0.2.5.beta2"
      gem "ruby-debug-ide"
    end
    ~~ (略) ~~
    
    
  3. docker-compose.yamlのCommandを修正
    例えば、修正前に以下の実行コマンドが記載されているとすると

    command: bash -c "bundle exec rails s -p 3000 -b '0.0.0.0'"
    

    このようにrdebug-ideを追加する。この時--portオプションはEdit ConfigurationのRemote portに合わせる。後半は修正前と同じ。

    command: bash -c "bundle exec rdebug-ide --debug --host 0.0.0.0 --port 1234 -- bin/rails s -p 3000 -b '0.0.0.0'"
    
  4. ポートを公開する。
    引き続きdokcer-compose.yamlでEXPOSE項目にport 1234を追加する。

    - "1234:1234"
    

デバッグする

  1. ホスト側でアプリケーションを立ち上げる

    $ docker-compose up
    
  2. RubyMineでデバッグ実行する。
    先ほどのConfigurationを指定して、虫マークをクリック
    Screenshot 2023-05-28 at 14.06.28.png
    虫マークが緑になり、ホスト側のターミナルでアプリケーションが立ち上がれば成功。
    Screenshot 2023-05-28 at 14.08.37.png

    web-1 | Puma starting in single mode...
    web-1 | * Puma version: 5.6.5 (ruby 2.7.8-p225) ("Birdie's Version")
    web-1 | *  Min threads: 5
    web-1 | *  Max threads: 5
    web-1 | *  Environment: development
    web-1 | *          PID: 1
    web-1 | * Listening on http://0.0.0.0:3000
    web-1 | Use Ctrl-C to stop
    
  3. あとは実行を止めたい箇所でブレイクポイントを設定すればOK。

終わりに

RubyMineの公式HPのDocker-composeと接続する方法だとうまくいかなかったりと大変でした。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1