RubyMine 2017.3 Help

Docker: Using Docker as a Remote Interpreter

Introduction

RubyMine integration with Docker allows you to run your applications in the variously configured development environments deployed in Docker containers.

Prerequisites

Make sure that the following prerequisites are met:

  • Docker is installed, as described on the page Docker Docs. 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

Download this project from GitHub and open it in RubyMine (File | Open).

Then, open the file route.rb (Ctrl+Shift+N) and add the following code:

root :to => 'projects#index'

Configuring Docker as a remote interpreter

Now that we've prepared our example, let's define a Docker-based remote interpreter.

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 option, from the drop-down lists select the Docker server (if the server is missing, click New...) and image name. If the image is missing, in the Terminal execute the following commands:

docker build .
and then
docker tag <image ID> docker_rails_sqlite

By the way, RubyMine suggests an intention action in the Gemfile for running the docker build . command:

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

Ruby interpreter path should have the default value:

/help/img/idea/2017.3/rm_choose_docker.png

As a result, in the Preferences dialog, Ruby SDK from the Docker 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_interpreter.png

Apply changes and close the dialog.

Running your application in a Docker container

As we have a Rails application, we should choose the environment (here it's Production) and execute the Rake command for migrations (db:migrate) in the Production environment. Next, select the Rails server for Production environment run/debug configuration and click /help/img/idea/2017.3/run.png:

The Run tool window shows the output:

/help/img/idea/2017.3/rm_docker_rails_run.png

Follow the suggested link, and see:

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

Docker tool window

But is it possible to see all the containers without the Terminal? RubyMine says - yes. You can use the Docker Tool Window as the UI for the Docker command-line client.

If you have configured Docker as a remote interpreter, you will see the Docker tool window button at the bottom side of the main RubyMine window:

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

Click this button and see that the Docker tool window successfully opens:

/help/img/idea/2017.3/rm_docker_tool_window.png

Let's look at this tool window more attentively. What do we see here?

  • First, we are connected to a Docker daemon:
    /help/img/idea/2017.3/rm_docker_tool_window_connected.png
  • Second, if we open the Run tool window, we'll see that the contents of the Console tab of the Run tool window is the same as the contents of the Log tab of the Docker tool window:
    /help/img/idea/2017.3/rm_correspondence_between_docker_and_run_tool_window.png
  • And finally, we see the strange names of the containers - they are human-readable and generated by Docker itself.

Summary

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

  • We downloaded a Rails project from GitHub and opened it.
  • We configured the remote interpreter.
  • We ran our Rails project in the Docker container.
  • Finally, we launched the Docker tool window and saw all the details visible in the Terminal.

See Also

Languages, Frameworks and Technologies:

Reference:

Last modified: 15 September 2017