Debugger not Working with Console with Ruby on Rails instance running on Docker container

Answered

Hi,

This is my second year using this product. But ever since I started using Docker to run my Rails server, I haven't been able to figure this out.

I need help setting up my debugger so it works with my Rails console. I have tried different approaches but can't seem to make it work. My debugger works perfectly fine with Specs or with my Server.

I basically end up using ByeBug due to this. Please point me in the right direction or documention solve this nagging issue once and for all.



1
10 comments

Hello,

We have a known issue for debugging consoles with docker and docker compose so could you please take a look at it and add your vote there.

0

ok, but has anyone been able to somehow make it work? Or is this a general thing; that is, the debugger doesn't work at all in Docker containers? If not, can you share any related articles, guides, threads, etc…

I found this article: https://www.jetbrains.com/help/ruby/remote-debugging-with-product.html#create_ruby_remote_debug
Does this apply to my case?

0

Debugger works if we speak about debugging Rails server or Ruby script, for example. Please check our tutorial about that:

https://www.jetbrains.com/help/ruby/using-docker-compose-as-a-remote-interpreter.html#debug_with_docker_compose

0

Yes, this works for me. I mean, if anyone has made it work for the rails console? I mean like executing any command on the rails console,  and being able to set breakpoints as usual (like when debugging the server as in your tutorial link)? 

0

SOLVED

After updating RubyMine to the latest version, and modifying the local path for my remote DSK, the debugger started working on my console. It's pretty neat! I had never used until now. It will be very handy in my daily work.

0

Hello Arturo,

That's interesting, thank you for sharing your solution. Using docker or docker compose interpreters doesn't require any editing for the paths of the added interpreter, and as far as I understood debugging Rails server and/or Ruby scripts worked for you. 

0

May it's because I build my docker container from my local project. Gems seem to need to be in sync between my local app and the remote app in my container. WHen the path mappings don't match, I usually have issues.

0

Would it be possible to provide more detailed steps on how you build your docker container? 

0

sure.

 

My setup is like this:

  • I have a dockerfile that looks like this:

Env setup:

  • MacOS: 14.2.1 (23C71)
  • Ruby version on Container: ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [aarch64-linux]
  • Ruby version in .ruby-version: 3.0.6
  • Ruby version locally installed in Project: ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [arm64-darwin22]

My RubyMine info:

  • RubyMine 2024.1.2
  • Build #RM-241.17011.76, built on May 21, 2024
  • Runtime version: 17.0.11+1-b1207.24 aarch64
  • VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
  • macOS 14.2.1
  • GC: G1 Young Generation, G1 Old Generation
  • Memory: 2048M
  • Cores: 8
  • Metal Rendering is ON
  • Registry:
     debugger.new.tool.window.layout=true
     ide.experimental.ui=true

Dockerfile

# Set the base image to the latest version of Ruby 3.0.6
FROM ruby:3.0.6

# Update the package index and install build-essential, Node.js, PostgreSQL client, ImageMagick, Graphviz, libvips, GnuPG, curl, and Git
RUN apt-get update -qq && apt-get install -y build-essential nodejs postgresql-client imagemagick graphviz libvips gnupg2 curl git

# Set the working directory to /app
WORKDIR /app

# Copy the Gemfile and Gemfile.lock into the container at /lynx-pay
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN gem install bundler -v 2.4.16
# Install the dependencies specified in the Gemfile
RUN bundle _2.4.16_ install

# Copy the entrypoint script into the container at /usr/bin/ and make it executable
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
COPY . .
# Set the entrypoint of the container to the entrypoint script
ENTRYPOINT ["entrypoint.sh"]

# Expose port 3000 for the Rails server
EXPOSE 3000

# Start the Rails server
CMD ["rails", "server", "-b", "0.0.0.0"]

# docker-compose.yml 

version: '3.8'

services:
  db:
    image: timescale/timescaledb:latest-pg14
    restart: always
    command: -c listen_addresses='*'
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - PGDATA=/var/lib/postgresql/data/timescaledb/
    ports:
      - "5433:5432"
    volumes:
      - db:/var/lib/postgresql/data
      - ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
    networks:
      - my-network

  redis:
    image: redis
    restart: always
    ports:
      - "6379:6379"
    command: redis-server --save 20 1 --loglevel warning
    networks:
      - my-network
    volumes:
      - redis:/data

  api:
    container_name: my-api
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0' && tail -f /dev/null"
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    depends_on:
      - db
      - redis
    stdin_open: true
    tty: true
    links:
      - db
      - redis
    networks:
      - my-network

Steps I followed to fix:

I basically followed the usual procedure to set up a remote interpreter, like in this post https://www.jetbrains.com/help/ruby/using-docker-compose-as-a-remote-interpreter.html#configure_remote_interpreter

The main difference is that in step 4 of Configure Compose as a remote interpreter , Select the added SDK in the Ruby SDK and Gems page and click OK.”, before hitting OK, I edited my “Path Mappings”, and instead of setting my Local Path to “/”, as I have always done, I used my complete local path to my project; e.g. “my_local_path/to_my_project/my_rails_app”. My remote path is just the usual “/app”.

That's how it works.

 

0

Thank you for the detailed answer, we'll check it. 

0

Please sign in to leave a comment.