LoginSignup
1
1

More than 3 years have passed since last update.

【ポートフォリオ を作成される方へ】Dockerでbinding.pryを使う方法

Posted at

ポートフォリオを作成中、dockerとCircleCIを使ってHerokuにデプロイするためにこちらの記事を参考に作っていました。
そこにbinding.pryを使いたいと思った時の導入の方法をお伝えしようと思います。

docker-compose.yml
version: '3'
services:
  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: root
    ports:
      - "4306:3306"

  web:
    build: .
    command: rails s -p 3000 -b '0.0.0.0'
    environment:
      RAILS_ENV: development
    volumes:
      - .:/sample_app #自身のアプリディレクトリ名を設定
    ports:
      - "3000:3000"
    links:
      - db

上記の状態から
①command: rails s -p 3000 -b '0.0.0.0'を削除
②tty: true

最終的な形はこちら

docker-compose.yml

version: '3'
services:
  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: root
    ports:
      - "4306:3306"
  web:
    build: .
    environment:
      RAILS_ENV: development
    volumes:
      - .:/sample_app
    ports:
      - "3000:3000"
    links:
      - db
    tty: true

③docker-compose up
④docker-compose exec web bash
⑤rails s -p 3000 -b '0.0.0.0'
⑥好きなとことに binding.pryを差し込む

参考

https://qiita.com/gakinchoy7/items/ae31107ef56efb16fe7e
https://stackoverflow.com/questions/35211638/how-to-debug-a-rails-app-in-docker-with-pry

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