RubyMine 2019.3 Help

Tutorial: Docker 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 as a remote interpreter for the sample Rails application. We'll set up and run the application in a single Docker container.

Prerequisites

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 Docker plugin is enabled.

  • Install Node.js and Yarn.

Build a Docker image

First of all, we need to build a Docker image for our application. To do this, open the Dockerfile. Press Ctrl+Shift+N, type Dockerfile and press Enter. Here you can see instructions for dockerizing our application based on the ruby image.

Dockerfile

Perform the following steps:

  1. Click Run on Docker in the gutter and select New Run Configuration from the menu.

  2. In the Edit Run Configuration dialog, specify the following settings:

    Docker run configuration
    • Specify the image name and tag in the Image tag field.

    • Disable the Run built image option because we'll run it later after assigning it as a remote interpreter.

    • Preview the resulting Docker command in Command preview.

    Click Run to start building the image.

  3. RubyMine displays the process of building the image in the Docker tool window.

    Docker tool window

    Wait until the image is built and displayed in the Images group.

    Docker tool window

Configure Docker as a remote interpreter

Now we can use the built image to configure a remote interpreter for our application because the image has the Ruby interpreter and required gems installed. To configure Docker as a remote interpreted, do the following:

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

  2. Click Add and select New remote... in the drop-down.

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

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

    • Image name - Select the image created in the previous chapter.

    • 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.

    Click OK.

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

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

    Docker tool window

Run the application

We can now migrate the database and run our Rails application:

  1. Migrate the database. To do this in RubyMine, press Ctrl twice and type db:migrate. Select rake db:migrate in the dropdown and press Enter. Leave the default settings in the invoked Execute 'db:migrate' dialog and click OK.

  2. Launch the application. Press Ctrl twice and start typing development. Select the Development: sample_rails_app_docker configuration from the list and press Enter. RubyMine will show the process of preparing the application to run in the Run tool window.

  3. Open a browser, enter the 0.0.0.0:3000 address, and press Enter to see our working application.

    Rails application in a browser
Last modified: 27 December 2019