binding.pry does not accept standard input in Docker (Rails 6.1Ruby 2.7.6) - Stack Overflow

I’m running a Rails 6.1.4 app (Ruby 2.7.6) in Docker, and I’m having issues with binding.pry.When the

I’m running a Rails 6.1.4 app (Ruby 2.7.6) in Docker, and I’m having issues with binding.pry. When the execution hits binding.pry, it opens correctly but does not accept any standard input — I cannot type or paste commands properly.

# docker-compose.yml (excerpt)
services:
  app:
    stdin_open: true
    tty: true

However, in both cases, when binding.pry is hit, standard input is either ignored or behaves unexpectedly. Is there any additional configuration I need for Docker or Rails to make standard input work with binding.pry?

However, I noticed that right after running

docker-compose build --no-cache

binding.pry sometimes works fine temporarily.

Has anyone experienced similar behavior or know why rebuilding the container would affect standard input in pry?

Environment: • Rails 6.1.4 • Ruby 2.7.6 • pry 0.14.2 • OrbStack Version 1.9.5 (18849) • OS: macOS

I tried using binding.pry in my Rails app running in Docker. I expected to be able to type commands when execution paused, but standard input was unresponsive or glitchy. I also tried enabling/disabling Spring and rebuilding the container.

I’m running a Rails 6.1.4 app (Ruby 2.7.6) in Docker, and I’m having issues with binding.pry. When the execution hits binding.pry, it opens correctly but does not accept any standard input — I cannot type or paste commands properly.

# docker-compose.yml (excerpt)
services:
  app:
    stdin_open: true
    tty: true

However, in both cases, when binding.pry is hit, standard input is either ignored or behaves unexpectedly. Is there any additional configuration I need for Docker or Rails to make standard input work with binding.pry?

However, I noticed that right after running

docker-compose build --no-cache

binding.pry sometimes works fine temporarily.

Has anyone experienced similar behavior or know why rebuilding the container would affect standard input in pry?

Environment: • Rails 6.1.4 • Ruby 2.7.6 • pry 0.14.2 • OrbStack Version 1.9.5 (18849) • OS: macOS

I tried using binding.pry in my Rails app running in Docker. I expected to be able to type commands when execution paused, but standard input was unresponsive or glitchy. I also tried enabling/disabling Spring and rebuilding the container.

Share Improve this question asked Mar 23 at 13:20 Fujiwara TakumiFujiwara Takumi 91 bronze badge 6
  • Could you show how did you define the services in docker-compose.yml ? And also post the command how do you start containers. Probably you'll need to bash in your running container – CR7 Commented Mar 23 at 13:38
  • ``` app: build: context: . dockerfile: path/to/Dockerfile command: bash -c "bundle install && bundle exec puma -e development" environment: RAILS_ENV: development volumes: - .:/app ports: - "3000:3000" stdin_open: true tty: true ``` Here’s a simplified and redacted version of my docker-compose.yml (only the relevant parts): – Fujiwara Takumi Commented Mar 23 at 14:17
  • ``` docker-compose up -d docker-compose attach XXXX ``` Let me know if you need any more details! – Fujiwara Takumi Commented Mar 23 at 14:19
  • When I use: ``` Pry.config.input = STDIN Pry.config.output = STDOUT binding.pry ``` – Fujiwara Takumi Commented Mar 23 at 14:23
  • it works — I can enter commands and interact with Pry normally. However, if I exit the Pry session using exit, everything continues to work fine the next time I hit binding.pry. – Fujiwara Takumi Commented Mar 23 at 14:25
 |  Show 1 more comment

2 Answers 2

Reset to default 0

If you really build your image with that compose keys (stdin_open: true, tty: true), this command will work

docker restart app && docker attach app

where app is container name

Depending on code reload strategy, you will need to run this command every time after adding debug line

I encountered the same issue, and I’d like to share what worked for me.

When I explicitly set the input and output for Pry like this:

Pry.config.input = STDIN
Pry.config.output = STDOUT
binding.pry

I was able to interact with the Pry session normally inside Docker.

However, I also noticed one important thing:

If I exit the Pry session by pressing Ctrl + D, then the next time I hit binding.pry, it sometimes doesn’t stop properly or ignores input.

To avoid this problem, I recommend using the exit command inside Pry to leave the session gracefully. That way, Pry continues to behave correctly in future debugging sessions.

Hope this helps others facing the same issue!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744285095a4566759.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信