How to debug a rails app in docker with pry? How to debug a rails app in docker with pry? docker docker

How to debug a rails app in docker with pry?


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/


as Gabe Kopley answer, assume your rails container is called app, set stdin_open and tty to true:

app:  stdin_open: true  tty: true

and I wrote a bash script to make life easier, save it to bin/dev:

#!/bin/bashdocker-compose up -d && docker attach $(docker-compose ps -q app)

don't forget to make dev be executable by chmod +x bin/dev

In your terminal, type bin/dev, it will automatically run up containers and attach the app container. when binding.pry called, you can type to the terminal directly.