Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 922
fey Avatar asked Feb 04 '16 21:02

fey


People also ask

How do I debug using pry?

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.

Can you debug in Docker?

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.


2 Answers

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

like image 158
Gabe Kopley Avatar answered Sep 28 '22 01:09

Gabe Kopley


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/

like image 39
Terri Chu Avatar answered Sep 28 '22 03:09

Terri Chu