Shiva Bhusal
Shiva's Blog

Follow

Shiva's Blog

Follow
Using pry-rails with Docker

Photo by Ian Taylor on Unsplash

Using pry-rails with Docker

Shiva Bhusal's photo
Shiva Bhusal
·Feb 27, 2023·

1 min read

Play this article

You might use binding.pry in your code but docker ignores the break-point. It won't allow interactivity and terminal to apps running in containers.

The problem is that Docker just kind of ignores it and moves on. In order to actually halt execution and use pry as normal, you have to these options to docker-compose.yml:

app:
  tty: true
  stdin_open: true

Source: stackoverflow.com/a/37264588/1042144

The next time binding.pry is executed, the process should halt and display an IRB-like console on the rails server screen. But you still can't use it directly. You have to attach a terminal to the docker container.

In order to attach to a docker container, you need to know what its ID is. Use docker ps to get a list of the running containers and their ids.

docker ps

Then you can use the numeric ID to attach to the docker instance:

docker attach 75cde1ab8133

It may not immediately show a rails console, but start typing and it should appear. If you keep this attached, it should show the rails console prompt the next time you hit the pry breakpoint.

 
Share this