ruby-on-railsdockerpry

How to debug a rails app in docker with pry?


I have a rails app running in a docker container in development environment.

When I try to debug it with placing binding.pry somewhere in the code and attaching to the container I can see the pry prompt in the output but it doesn't pause on it and I can't interact with it like it was without docker container.

So how do I debug a containerized app?


Solution

  • If you're using docker-compose, you can add these flags to docker-compose.yml:

    app:
      tty: true
      stdin_open: true
    

    And then attach to your process with docker attach project_app_1. pry-rails works here now. Ensure less is installed on your container for the optimal pry experience.

    cf. https://github.com/docker/compose/issues/423#issuecomment-141995398