RubyMine 2017.3 Help

Using Docker Compose as a Remote Interpreter

Prerequisites

Make sure that the following prerequisites are met:

  • Docker is installed. You can install Docker on the various platforms, but here we'll use the mac OS installation.

    Note that you might want to repeat this tutorial on different platforms; then use Docker installations for Windows and Linux (Ubuntu, other distributions-related instructions are available as well).

  • Before you start working with Docker, make sure that the Docker Integration plugin is enabled. The plugin is bundled with RubyMine and is activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.

  • Before you start working with Docker, make sure that the Ruby Docker plugin is enabled. The plugin is bundled with RubyMine and is activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.

Preparing an example

We'll use the same example as for Docker. So download the project from GitHub and open it (File | Open).

Adding files for Docker and Docker-Compose

In the Project tool window, right-click the project root and choose New | File (Alt+Insert), enter the file name (here Dockerfile) and enter the following code:

FROM ruby:2.3.3 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs RUN mkdir /myapp ADD Gemfile /myapp/Gemfile ADD Gemfile.lock /myapp/Gemfile.lock RUN bundle install ADD . /myapp

Next, repeat the same steps for the docker-compose.yml file and enter the following code:

version: '2' services: web: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - .:/myapp ports: - "3000:3000"

Configuring Docker

Now that we've prepared our example, let's configure Docker. To do that, open Preferences dialog (Ctrl+Alt+S or click /help/img/idea/2017.3/settings.png on the main toolbar) and click the Docker page under the Build, Execution, Deployment node. Click /help/img/idea/2017.3/add.png to create a Docker server.

Accept the suggested default values:

/help/img/idea/2017.3/rm_docker_settings.png

Next, apply changes.

Configuring Docker Compose as a remote interpreter

Let's now define the remote interpreter based on Docker-Compose.

To do it, open the Preferences dialog (press Ctrl+Alt+S or click /help/img/idea/2017.3/settings.png on the main toolbar).

Next, click the Ruby SDK and Gems page. On this page, click + and choose New remote...:

/help/img/idea/2017.3/rm_choose_remote.png

In the dialog box that opens, select the Docker-Compose option, from the drop-down list select the Docker server (if the desired server is missing, click New...), Docker-Compose configuration file (here docker-compose.yml, click the browse button to find the required file), choose the desired service (here web) and Ruby interpreter path:

/help/img/idea/2017.3/rm_choose_docker_compose_1.png

Then you can take your time waiting while RubyMine gets your remote interpreter and installs the required gems:

/help/img/idea/2017.3/rm_docker_compose_up.png

Finally, in the Preferences dialog, Ruby SDK from the Docker-Compose container should appear in the list of available SDKs, marked with the 'Remote' prefix. Later, you have to select this new interpreter as the project interpreter, by selecting the corresponding radio-button:

/help/img/idea/2017.3/rm_docker_compose_remote_interpreter.png

Apply changes and close the dialog.

Using the Docker tool window

Since we've configured Docker, the Docker tool window button appears at the bottom of RubyMine's main window:

/help/img/idea/2017.3/rm_docker_tool_window_button.png

Click this button and see your container running:

/help/img/idea/2017.3/rm_docker_running_container.png

Running your application under Docker-Compose

First, as we are executing a Rails application, we must run a migration.

To do that, on the main menu choose Tools | Run Rake Task... and in the dialog box that opens, start typing migrate:

/help/img/idea/2017.3/rm_run_rake_task_migration.png

Choose db:migrate. The migration is executed.

Next, create the ordinary Rails server run/debug configuration. To do that, on the main menu choose Run | Edit Configurations...; in the dialog box that opens click + and select Rails.

Launch this configuration (Run | Run 'Production:DockerRailsSQLite'):

/help/img/idea/2017.3/rm_docker_compose_run.png

To see output in your web browser, follow the link:

/help/img/idea/2017.3/rm_docker_rails_run_output.png

Debugging your application under Docker-Compose

These gems should be written to the Gemfile of your project:

gem 'debase' gem 'ruby-debug-ide'

For example:

/help/img/idea/2017.3/rm_debug_gems.png

Next, execute the docker build . command. By the way, RubyMine suggests an intention action in the Gemfile for running the docker build . command (if these gems are missing):

/help/img/idea/2017.3/rm_docker_build_intention.png

Next, let's launch our Rails application in the debug mode under Docker Compose. To do that, set a breakpoint and on the main menu choose Run | Debug 'Production:DockerRailsSQLite', or just click /help/img/idea/2017.3/debug.png next to the run/debug configuration drop-down with the Production:DockerRailsSQLite run/debug configuration selected:

/help/img/idea/2017.3/rm_debug_docker_rails_app.png

The result is shown below:

/help/img/idea/2017.3/rm_docker_compose_rails_app_debug.png

Summary

Let's summarize what has been done with the help of RubyMine:

  • We downloaded a Rails application from GitHub and opened it.
  • We added specific Docker Compose files to our project.
  • We configured the remote interpreter based on Docker Compose.
  • We ran our Rails application in the Docker Compose container.
  • We debugged our Rails application in the Docker Compose container.
  • Finally, we launched the Docker tool window and saw the details visible in the Terminal.

See Also

Languages, Frameworks and Technologies:

Reference:

Last modified: 15 September 2017