RubyMine 2019.2 Help

Using Docker Compose as a Remote Interpreter

RubyMine provides various capabilities for working with Docker run on your machine. You can learn more in the Docker topic.

This tutorial describes how you can use Docker Compose as a remote interpreter for the sample Rails application. This application consists of a database backend and a web frontend. We'll configure the application to run it using two separate services and try debugging capabilities.

Install Docker and open a sample application

In this tutorial, we’ll use Mac with macOS, with RubyMine installed. Moreover, the following prerequisites should be met to complete all steps:

  • Verify that Docker is installed and running.

  • Make sure that the Ruby Docker and Docker Integration plugins are enabled.

  • Open the following Rails application in RubyMine:

    https://rubyminedoc@bitbucket.org/rubyminedoc/sample_rails_app_docker.git

Build and run the application with Compose

In this chapter, we'll run out application in two separate services: web for a front-end and db for a database. To do this, we need to reconfigure database settings in the database.yml file. Then, we can run docker-compose up. Perform the following steps:

  1. Go to the config/database.yml file and comment Ctrl+/ the following code:

    development: <<: *default adapter: sqlite3 database: db/development.sqlite3
  2. Uncomment Ctrl+/ the part that configures using the Postgres database for the development environment:

    development: <<: *default adapter: postgresql encoding: unicode host: db username: postgres password: database: sample_rails_app_db
  3. Open the docker-compose.yml file. Note that the following command is used for the web service to keep it running:

    web: # command: tail -f /dev/null

    We need the web service running because RubyMine uses the docker-compose exec command internally to add Docker Compose as a remote interpreter.

  4. Click docker-compose up in the gutter and wait until Docker Compose pulls/build the images and starts containers.

    Docker tool window: Compose

    Alternatively, you can run the docker-compose up command in the RubyMine terminal.

Configure Compose as a remote interpreter

  1. Open the Settings/Preferences dialog Ctrl+Alt+S, go to the Languages & Frameworks | Ruby SDK and Gems page.

  2. Click the Add button and select New remote....

    New remote interpreter
  3. In the invoked dialog, select Docker Compose and specify the following options:

    Configure remote Ruby interpreter: Docker Compose
    • Server - This option specifies a Docker server used to run a container.

    • Configuration file(s) - Leave the docker-compose.yml file.

    • Service - Select the web service.

    • Ruby or version manager path - Leave the default ruby value to detect a path to the Ruby interpreter automatically. You can also manually specify the path to the interpreter or the version manager executable.

  4. Select the added SDK in the Ruby SDK and Gems page and click OK.

    Ruby SDK and Gems: Docker Compose
  5. Wait until RubyMine finishes the indexing process and creates helper Docker images and containers.

    Docker tool window: Helpers

Create a database and run migrations

Before debugging our Rails application, we need to create the database and run migrations.

  1. Press Ctrl twice and type db:create. Select rake db:create in the dropdown and press Enter. Leave the default settings in the invoked Execute 'db:create' dialog and click OK.

  2. Finally, to migrate the database, press Ctrl twice, type db:migrate, select db:migrate in the dropdown and press Enter. Click OK in the invoked dialog.

Install debugging gems and set a breakpoint

To debug the application with Docker Compose, we need to install debugging gems to our remote interpreter:

  1. Open the Gemfile and uncomment Ctrl+/ the following lines of code:

    gem 'debase' gem 'ruby-debug-ide'
  2. Place the caret at any of these gems and press Alt+Enter. In the popup, select Run 'docker-compose build', press Enter and wait until RubyMine installs these gems.

  3. Open the users_controller.rb file and set a breakpoint within the create method next to the line where a new user is created.

    Set a breakpoint

Compose run/debug configuration settings

Before running a debugging session, let's examine startup settings related to Docker Compose:

  1. Press Ctrl+Shift+A and start typing edit configurations. Select Edit Configurations and press Enter.

    Find Action
  2. In the invoked Run/Debug Configurations dialog, select the Development configuration under the Rails node.

    Run/Debug Configurations dialog

    In the docker-compose group, you can see the following options for running/debugging Rails applications:

    • docker-compose exec - RubyMine runs a command in an already running container.

    • docker-compose up - RubyMine starts a service used as a remote interpreter with additional settings (for example, exposes additional ports required for the debugger). This is the recommended way to start the debugging session.

    • docker-compose run - RubyMine runs a comman in a new container.

    Leave the default docker-compose up and click OK.

Start debugging

Now we are ready to debug the application:

  1. Click Debug Shift+F9 to start debugging. In the invoked dialog, select Patch project config.

  2. Open a browser and specify the application address 0.0.0.0:3000.

    Rails application in a browser
  3. Click the Sign up now! button. On the Sign up page, enter the required user parameters and click Create my account.

    Sign up page
  4. The debugger pauses its session on a breakpoint and enables you to examine the application state.

    Debugging an application

    For instance, you can check user parameters specified on the Sign up page.

Last modified: 5 September 2019