Tutorial: Docker as a remote interpreter
Docker is a tool for building, sharing, and running containerized applications. RubyMine provides integration with Docker and allows you to perform all the required actions in your project - from building images to executing commands inside running containers. Moreover, RubyMine enables you to use the running Docker container as a remote interpreter. This means that you can run, debug, and test your application in an isolated environment right from the IDE.
This tutorial describes how you can use Docker as a remote interpreter for running a sample Ruby application (the docker branch).
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.
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.
Perform the following steps:
Click in the gutter and select New Run Configuration from the menu.
In the Edit Run Configuration dialog, specify the following settings:
Specify the image name 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.
RubyMine displays the process of building the image in the Services tool window. Wait until the image is built and displayed in the Images group.
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 interpreter, do the following:
Open the Settings/Preferences dialog Ctrl+Alt+S, go to the Language & Frameworks | Ruby SDK and Gems page.
Click and select New remote... in the drop-down.
In the invoked dialog, select Docker and specify the following options:
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.
Select the added SDK in the Ruby SDK and Gems page and click OK.
Wait until RubyMine finishes the indexing process and creates helper Docker images and containers.
Run the application
We can now run a Ruby script using a configured remote interpreter:
Press Ctrl twice and type the following command:ruby script.rb
In the Run tool window, type any name and press Enter to see a program's response.