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?
The Ruby programmer can invoke the pry console during runtime by inserting the line 'binding. pry' wherever they would like to stop the program. When the interpreter hits the binding. pry, Pry will open a REPL session in the console, allowing you to test variables, return values, iterations, and more.
You can run and debug your apps in Linux or Windows containers running on your local Windows desktop with Docker installed, and you don't have to restart the container each time you make a code change.
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
to use pry you have to run it differently:
docker-compose run --service-ports web
check out this article for more info:
http://blog.carbonfive.com/2015/03/17/docker-rails-docker-compose-together-in-your-development-workflow/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With