Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Furqanameen/8977fc9d21c346972e5166634f2b6103 to your computer and use it in GitHub Desktop.
Save Furqanameen/8977fc9d21c346972e5166634f2b6103 to your computer and use it in GitHub Desktop.
Rails binding.pry usage with docker
  1. Initially install your pry-rails to group development on your apps Gemfile
group :development do
  # ..
  gem 'pry-rails'
  # ..
end
  1. Then make sure that your docker-compose.yml contains in the app container the following two:
app:
  ..
  ..
  tty: true
  stdin_open: true
  1. Add binding.pry to the desired place you want to have a look on your rails code:
def index
  binding.pry
end
  1. Run your docker app container and get the container id
docker-compose up app

and open a seperate terminal to run docker ps and get the container id:

docker ps

and you will get something like the following:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES
e5410d059f31        mariadb:10.1        "docker-entrypoint..."   13 days ago         Up 13 days          3306/tcp                           msdsecs_mariadb_1
2557eef7f95c        redis               "docker-entrypoint..."   13 days ago         Up 13 days          6379/tcp                           msdsecs_redis_1
5fd1e9f0d850        msdsadd_sidekiq     "/app/docker_helpe..."   7 weeks ago         Up 42 hours         3000/tcp, 0.0.0.0:6666->6666/tcp   msdsadd_sidekiq_1
a38aaff4b63e        mariadb:10.1        "docker-entrypoint..."   3 months ago        Up 42 hours         3306/tcp                           msdsadd_mariadb_1
f2c0047944dd        redis               "docker-entrypoint..."   3 months ago        Up 42 hours         6379/tcp                           msdsadd_redis_1

With container id in hand, you can attach the terminal to the docker instance:

docker attach e5410d059f31

where e5410d059f31 is the container id of the app. You will get your pry on the attached terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment