Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug rails application which is running inside docker container

I am trying to execute debugger in rails application which uses docker.Our application server executes in Ubuntu terminal using: docker-compose up. I did not find the way to run the debugger. We can't use rails s --debugger. What's the way to debug our rails application which is integrated with docker. When I keep debugger in application file we get output in console: {***** Debugger requested, but was not available (ensure ruby-debug is listed in Gemfile/installed as gem): Start server with --debugger to enable ***** }

like image 844
Bharat Bhushan Avatar asked Jul 02 '15 11:07

Bharat Bhushan


People also ask

Can you debug a docker container?

Debug containerized apps. With version 0.9. 0 and later, the Docker extension provides more support for debugging applications within Docker containers, such as scaffolding launch. json configurations for attaching a debugger to applications running within a container.


1 Answers

I don't know ruby or rails, but this is general "problem" with docker-compose up. The code execution will not stop in a running container in this case and instead fail when you hit a point for the debugger. You need to run the service in the foreground instead:

docker-compose stop <my-service-to-debug>
docker-compose run --service-ports <my-service-to-debug> 

This will drop you into the debugger once your code hits that point. The important part here is the --service-ports flag which makes sure the same ports are exposed as you specified in your docker-compose.yml file. You can also use the --no-deps flag in case you don't want any linked containers to restart.

like image 193
Torsten Engelbrecht Avatar answered Sep 28 '22 17:09

Torsten Engelbrecht