8
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Docker環境でbinding.pryを使用→binding.pryで処理が止まらない

Posted at

概要

pry-byebugを使ってデバッグしようとしたところ、binding.pryで動作が止まらずデバッグできなかった。

目次

環境

Ruby 3.1.2
Rails 7.0.3

現状

このようにデバッカーの入力待ちにならず、HTMLが生成されてしまいます。

my_app $ docker attach my_app_web_1
Started GET "/boards/new" for 172.18.0.1 at 2022-08-13 11:38:59 +0000
Processing by BoardsController#new as HTML
  Rendering layout layouts/application.html.erb
  Rendering boards/new.html.erb within layouts/application
  Rendered boards/new.html.erb within layouts/application (Duration: 1.6ms | Allocations: 870)
  Rendered layouts/_header.html.erb (Duration: 0.0ms | Allocations: 17)
  Rendered layout layouts/application.html.erb (Duration: 30.0ms | Allocations: 4102)
Completed 200 OK in 34ms (Views: 32.3ms | ActiveRecord: 0.0ms | Allocations: 4455)

対策

調べたところ、binding.pryで止めるためにdocker-compose.ymlの設定をいじらないといけないと判明。
app:またはweb:のところに以下のコードを追加するだけです。

tty: true
    stdin_open: true

全体的にこんな感じ

web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/my_app
    ports:
      - "3000:3000"
    depends_on:
      - db
    tty: true
    stdin_open: true

結果

Started GET "/boards/new" for 172.18.0.1 at 2022-08-13 11:54:18 +0000
Processing by BoardsController#new as HTML

From: /my_app/app/controllers/boards_controller.rb:9 BoardsController#new:

    6: def new
    7:   @board = Board.new
    8:   binding.pry
 => 9: end

[1] pry(#<BoardsController>)>

無事に止まりました。

おわりに

自分と同じ状態で困ってる方の役に立てれたらうれしいです:relaxed:

8
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
8
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?