29

I want to use byebug to debug my application but the app is never stop although I already put byebug inside my code. Here is my Gemfile.

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console

  gem 'byebug', '~> 5.0.0'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

end

I put byebug in one of my controller.

def edit
  byebug
  present Ingredient::Update
end

I already made all my request local in my development.rb. I already restart the server a couple times.

config.consider_all_requests_local       = true

Here is the example stack trace that byebug only print the first trace and then the app keeps going on executing the next line.

web_1 | [43, 52] in /recipe/app/controllers/ingredients_controller.rb
web_1 |    43:   def update
web_1 |    44:     run Ingredient::Update do |op|
web_1 |    45:       return redirect_to op.model
web_1 |    46:     end
web_1 |    47:     byebug
web_1 | => 48:     render action: :edit
web_1 |    49:   end
web_1 |    50:
web_1 |    51:   # DELETE /ingredients/1
web_1 |    52:   # DELETE /ingredients/1.json
web_1 | (byebug)   Rendered ingredients/edit.haml within layouts/application (264.1ms)
web_1 |   Rendered layouts/_navigation.haml (45.0ms)
web_1 | Completed 200 OK in 2827ms (Views: 2764.0ms | ActiveRecord: 3.9ms)
web_1 |
web_1 |
web_1 | Started GET "/assets/application.self-1ca8529ef221ef9dba25e835f258c4e62f2f49bce400273a67e63d7d73be28ba.css?body=1" for 192.168.59.3 at 2015-07-28 06:46:00 +0000

Any idea? Update I use docker-compose and docker inside my Rails app.

Edwin Lunando
  • 2,726
  • 3
  • 24
  • 33

2 Answers2

101

When using docker-compose in combination with byebug this needs to be added to make it work properly. Found in this blog post

Add this to docker-compose.yml

web:
  ...
  stdin_open: true
  tty: true

Then run docker-compose in deamonized mode and attach to the web container with docker:

docker-compose up -d
docker attach myappname_web_1
pgericson
  • 1,884
  • 2
  • 17
  • 21
  • 2
    Note that it's not necessary to run your services in detached mode. Also when you attach to the container, it'll appear as if it's hanging, but as soon as that container's app receives a request, you'll see logger output. – Abraham Sangha May 19 '17 at 17:15
  • 7
    Do not use docker attach myappname_web_1. Instead, run "docker container ls" to get the containers running, and then find the id of the one you are working on. Then, just run: "docker attach container_id" – yorgos Nov 08 '17 at 10:20
  • 3
    What to do if it does not halt on the actual instruction? It just prints it out and continues executing – Dmitri Jun 20 '19 at 08:24
  • Can someone explain why it doesn't work when container name is provided instead of id as mentioned in the comment above? – DDMC Aug 25 '21 at 10:51
18

To enable debugger mode:

docker-compose run --service-ports web

See this blog post

Soviut
  • 88,194
  • 49
  • 192
  • 260
Chryus
  • 181
  • 2
  • 2