[Ruby] [For those who create portfolios] How to use binding.pry with Docker

less than 1 minute read

While creating the portfolio, I was making it by referring to this article to deploy to Heroku using docker and CircleCI.
I will tell you how to introduce it when you want to use 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 #Set your own app directory name
    ports:
      - "3000:3000"
    links:
      - db

From the above state
① command: rails s -p 3000 -b Delete ‘0.0.0.0’
②tty: true

Click here for the final shape

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’
⑥ Insert binding.pry as you like

reference

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