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?
If you don't use
docker-compose
though, you can simply run the container with-it
option.For example:
as Gabe Kopley answer, assume your rails container is called
app
, setstdin_open
andtty
totrue
:and I wrote a bash script to make life easier, save it to
bin/dev
:don't forget to make
dev
be executable bychmod +x bin/dev
In your terminal, type
bin/dev
, it will automatically run up containers and attach the app container. whenbinding.pry
called, you can type to the terminal directly.If you're using docker-compose, you can add these flags to
docker-compose.yml
:And then attach to your process with
docker attach project_app_1
.pry-rails
works here now. Ensureless
is installed on your container for the optimal pry experience.cf. https://github.com/docker/compose/issues/423#issuecomment-141995398
I had this same issue when I was running pry in Passenger. Try changing
"pry-rails"
in the Gemfile togem "pry-remote"
, which will initiate a dRuby, or distributed protocol with no dependencies.Where you want to stop the code in execution call
"binding.remote_pry"
as opposed to"binding.pry"
Then just call
remote-pry
in the console to access it. It should work the same. In your test environment just the usualbinding.pry
works fine.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/