netcat_dd
netcat_dd

Reputation: 29

"undefined method `pry'" error inside rails container although pry-rails gem is installed and required

I am running public ruby on rails web app docker image (gitlab) inside the container that I initialize with docker compose run --service-ports --detach [SERVICE_NAME] command.

My goal is to debug the specific function inside image's source code using binding.pry breakpoint. To avoid problems with initial bundle install, I install nessesary pry-rails gem using docker exec [CONTAINER_ID] /bin/bash && gem install pry-rails.

I am getting an undefined method error although pry-rails gem is installed and required.

Corresponding logs from docker attach instance:

==> /var/log/gitlab/gitlab-rails/production.log <==
  
ActionView::Template::Error (undefined method `pry' for #<Binding:0x00007ff556ce52b8>
Did you mean?  try):

Here is the confirmation that pry-rails is installed:

root@3cbe23da9b57:/# gem list | grep pry-rails
pry-rails (0.3.9)

root@3cbe23da9b57:/# gem which pry-rails
/opt/gitlab/embedded/lib/ruby/gems/3.0.0/gems/pry-rails-0.3.9/lib/pry-rails.rb

pry-rails is required inside the Gemfile using the following code block:

group :development, :test do
  gem 'pry-rails', '~> 0.3.9'
end

gem env output:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.4.14
  - RUBY VERSION: 3.0.6 (2023-03-30 patchlevel 216) [x86_64-linux]
  - INSTALLATION DIRECTORY: /opt/gitlab/embedded/lib/ruby/gems/3.0.0
  - USER INSTALLATION DIRECTORY: /root/.local/share/gem/ruby/3.0.0
  - RUBY EXECUTABLE: /opt/gitlab/embedded/bin/ruby
  - GIT EXECUTABLE: /opt/gitlab/embedded/bin/git
  - EXECUTABLE DIRECTORY: /opt/gitlab/embedded/bin
  - SPEC CACHE DIRECTORY: /root/.local/share/gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /opt/gitlab/embedded/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-linux
  - GEM PATHS:
     - /opt/gitlab/embedded/lib/ruby/gems/3.0.0
     - /root/.local/share/gem/ruby/3.0.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => true
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /opt/gitlab/embedded/bin
     - /opt/gitlab/bin
     - /assets
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin

Upvotes: 1

Views: 440

Answers (1)

smathy
smathy

Reputation: 27961

Your docker container (based on the log file you quoted from) is in the production environment, so will not be loading the gems from that :development, :test block. You can confirm pry-rails is not loaded with: Gem.loaded_specs.keys.include? "pry-rails"

Upvotes: 0

Related Questions