Develop and debug Rails app using Docker container.
graph LR
Browser -- http : 3000 --> rails-server
subgraph VSCode
debugger
end
subgraph "Dev Container"
direction TB
rails-server["rails server (Puma)"]
debugger -- attach : 1234 --> rdebug-ide
rdebug-ide -- debugs --> rails-server
end
- Rails app and debugger runs inside Docker container
- VSCode debugs into it with remote debugging
- Rails app access via HTTP
- Setup development environment quickly and consistently - minimal setup on host
- Ensure dev environment closely match production (same / almost same image)
-
Start-up dev container (may take a while to build on first run)
./debug-app.sh
-
Press F5 to attach VSCode debugger to dev container
-
Add a breakpoint (e.g. to debugtest_controller.rb line 5)
-
Debug away 🙂 (e.g. go to http://localhost:3000/debugtest)
To get a shell into container (e.g. to run irb
/ rails console
):
./bash-shell-rails_debug.sh
Then run whatever command you want.
Tip: For advanced needs, use docker exec
- see bash-shell-rails_debug.sh for example.
To stop and remove container:
./clean-up-debug-rails.sh
To get things like code completion, navigation ("intellisense") for VSCode, install these on host:
# Install ruby language support
vscode --install-extension rebornix.Ruby
# Enable code completion, navigation ("intellisense")
sudo gem install solargraph
vscode --install-extension castwide.solargraph