0
0

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 3 years have passed since last update.

dockerでbinding.pry

0
Last updated at Posted at 2021-05-15

Dockerでbinding.pryするには設定が必要だった。

アタッチということをしなければいけないらしい

Gemfileに下記を記載

Gemfile
group :development do
  gem 'pry-byebug'
end

docker-compose.ymlファイルに下記の2つを設定する
stdin_open: true tty: true

docker-compose.yml
back:
    build: back/
    command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    stdin_open: true #追記
    tty: true  #追記
    env_file:
      - ./back/environments/db.env
    # 以下省略

Gemfileを変更したので、buildしなおす

Dockerfileがある場合
今回の場合
Dockerfileの中に下記のような記述があり、再度読み込みをしなければいけない
bundle installやbundle updateコマンドは使用しないでもbuildし直すことで構築される。

CMD ["bundle", "exec", "rails", "s", "puma", "-b", "0.0.0.0", "-p", "3000", "-e", "development"]
$ docker-compose build

検証場所にbinding.pryを記述

$ docker-compose up

別のターミナルで

アタッチ

$ docker attach <コンテナNAME or ID>

$ docker ps
でNAME、IDは確認できます

検証すると...

    13:     else
    14:      binding.pry
 => 15:       User = User.find_by(name: '山田')
// 省略
> 

止まった!

デバッグから出る

$ exit

アタッチから出る

control + P -> control + Q

Control + D or C だとコンテナが停止してしまうので上記で安全にデタッチしましょう!!

番外

デバッグ終えてフォルダをみると
コマンドのログが書かれたファイルが生成されています。
gitignoreに記載しておきます。

gitignore
/.ash_history
/.local/*

アタッチってそもそも何?

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?