Home>

I want to debug using pry on rails.
Therefore, I installed the gem, wrote binding.pry in an arbitrary place, and executed it, but the console did not work.
As for the development environment, since we are using the docker environment, we found that it was necessary to check the console inside the container.
From this, I modified it so that pry can be used even in the docker environment.

version: '3'
services: services:
  app:
    build:
      context: ..
    environment: environment:
      RAILS_ENV: development
      MYSQL_ROOT_PASSWORD: db_root_password
      MYSQL_USER: app
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: my_app_development
      DATABASE_HOST: db
    command: bundle exec puma -C config/puma.rb
--------------------- ↓ Two newly added lines ↓
    stdin_open: true
    tty: true
---------------------
    volumes:
      --.:/My_app
      --public-data:/my_app/public
      --tmp-data:/my_app/tmp
      --log-data:/my_app/log
    depends_on:
      --db
  db:
    image: mysql: 5.7
    environment: environment:
      MYSQL_ROOT_PASSWORD: db_root_password
      MYSQL_USER: app
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: my_app_development
      DATABASE_HOST: db
    volumes:
      --db-data:/var/lib/mysql
    ports: ports:
      -"33 16: 3306"
  web:
    build:
      context: containers/nginx
    volumes:
      --public-data:/my_app/public
      --tmp-data:/my_app/tmp
    ports: ports:
      -"3000:80"
    depends_on:
      --app
volumes:
  public-data:
  tmp-data:
  log-data:
  db-data:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a43a90dcab74 my_app_web "/ bin/sh -c'/ usr/sb…" 42 minutes ago Up 42 minutes 0.0.0.0:3000->80/tcp my_app_web_1
00f15cac162f my_app_app "bundle exec puma -C…" 42 minutes ago Up 42 minutes my_app_app_1
00d88ac1c7a9 mysql: 5.7 "docker-entrypoint.s…" 6 days ago Up 42 minutes 33060/tcp, 0.0.0.0:3316->3306/tcp my_app_db_1
class UsersController</pre>
<pre><code data-language = "terminal">$docker attach my_app_app_1


It should work with, but it does not work even if reloaded with a browser or command, and it is in a state where debugging is not possible.
What are the possible causes?
The sites I referred to are as follows
Run binding.pry on docker

  • Answer # 1

    For debugging, I gave up the dcoker environment and made it work on the host.

Related articles