Search⌘ K
AI Features

Debugging

Explore how to debug a Dockerized Rails application using byebug and interactive docker-compose commands. Learn to halt and resume requests during debugging, handle server startup issues, and ensure smooth testing of your Rails controllers within a Docker environment.

We'll cover the following...

Byebug debugger

No chapter on testing would be complete without some mention of how to debug our application when it is not behaving as we would expect. Imagine there is a problem with our welcome_controller.rb.

Let’s use the byebug debugger that is included as standard with a Rails app. Let’s add a byebug breakpoint to our welcome_controller.rb:

Ruby
class WelcomeController < ApplicationController
def index
redis = Redis.new(host: "redis", port: 6379)
redis.incr "page hits"
@page_hits = redis.get "page hits"
byebug
end
end

In case your Rails server is up, you need to stop it:

$ docker-compose stop web

When we want an interactive ...