How to work with Docker/Docker Compose from RubyMine

Posted on by Andrey Aksenov


RubyMine 2019.1
has a bunch of capabilities which allow you to work with Docker and Docker Compose. You can inspect existing images and containers, quickly edit Docker files using autocompletion, create new images and start services directly from the IDE, and run or debug your application using Docker SDK. Let’s take a look at how to do all this.

You can play with RubyMine Docker features using the following application containing Dockerfile and docker-compose.yml:
https://bitbucket.org/rubyminedoc/sample_rails_app_docker/

Enable Docker support

RubyMine provides Docker support by means of the Ruby Docker and Docker Integration plugins bundled with the IDE. To start working with Docker, first make sure it’s running, and then start up RubyMine. In the main menu, select View | Tool Windows | Docker. In the invoked Docker tool window, click configure to establish a connection to Docker.
configure connection

Starting with v2019.2, Docker containers and services are managed in the Services tool window. Learn more at the following blog post: Services tool window: One place to rule them all.

Click the plus button in the Settings/Preferences dialog. RubyMine will automatically choose the required way to connect to Docker.
connection settings
Click OK and then click the run button in the Docker tool window to establish a connection to Docker and see the available images, containers, and services.
docker tool window

Work with images and containers

After you’ve connected to Docker, you can select images or containers and see their properties in the right-hand pane.
item properties
In the context menu of specific entities, you can perform various actions, for example, start and stop containers, inspect their properties, and so on.
item actions
You can push images to the preconfigured Docker repository.
push image
You can configure the registry settings in Settings/Preferences | Build, Execution, Deployment | Docker | Registry.
registry settings

Build new images and start services

Let’s take a look at how RubyMine can help you edit Docker files (Dockerfile and
docker-compose.yml), build new images from them, and start containers and services.
When editing a Dockerfile, RubyMine allows you to autocomplete its instructions.
dockerfile completion
Once the Dockerfile is ready, you can build an image from it. Click the button in the gutter and choose New Run Configuration.
new run configuration
In the Edit Run Configuration dialog, you can specify all the required settings for building an image. In the example below, we specified the image tag, enabled the Run build image option to run the image in a container after building, and bound the host and container ports.

dockerfile run configuration
In Command preview, make sure that the generated Docker command is correct and click Run to build an image. Then, wait until RubyMine has built the image and then run it in a container.
docker tool window
That’s it!

Use Docker/Docker Compose as a remote interpreter

One of the most powerful advantages of working with Docker is it can be used as a remote interpreter. When working with Rails applications, you can perform several useful actions inside a container: run migrations, install additional gems, and so on. For example, to use Docker as a remote interpreter, open the Settings/Preferences dialog on the Ruby SDK & Gems page, click the + button and select New remote. Then, choose Docker as a remote interpreter and select the required image.
remote docker sdk
Click OK and choose the SDK as a project interpreter. When you click OK in the Settings/Preferences dialog, RubyMine will start indexing your project using the added Docker SDK. After RubyMine loads the Docker SDK, you can start working with your application.

Now let’s see on how to work with Docker Compose inside the IDE. When you are editing the docker-compose.yml file, autocompletion is also available as it is for a Dockerfile.
docker compose completion
After you’ve finished editing, start your services by clicking the docker-compose up button.
docker compose up
RubyMine then pulls/rebuilds required images and runs both services.
docker compose
To use Docker Compose as a remote interpreter, take the same steps as you have for Docker and don’t forget to choose the service that acts as a remote interpreter.
remote docker compose sdk
Click OK, then click OK in Settings/Preferences to allow RubyMine to download all the required gems from the remote interpreter. That’s it – you can now run or debug your application under Docker Compose!

Docker support updates in v2019.1

With v2019.1, RubyMine extensively uses the docker-compose exec command internally to speed up remote development. This affects running/debugging an application, installing gems, running rake tasks, and so on.

  • Run/debug configuration changes
    The main change is that in 2018.3 and earlier versions, RubyMine always uses the docker-compose up command internally to run an application. Starting with v2019.1, docker-compose exec is used by default. If required, you can configure your run/debug configurations to return to the old behavior. You can also use docker-compose run to start up your environment in new containers.
    development settings
  • Installing gems
    In v2018.3 and older, you can install new gems by rebuilding the underlying Docker images.
    docker compose build
    With v2019.1, new gems can be quickly installed into a running container.
    install gems
  • Using ‘exec’ for running internal commands
    For the 2018.3 and earlier versions, RubyMine uses docker-compose up for all the internal commands required for working with a remote Docker interpreter. This means that performing a command creates a new service Docker container.
    containers
    Starting with v19.1, you can try our new experimental capability that speeds up performing internal RubyMine actions using the docker-compose exec command run within a single service container.
    containers
    To enable this feature, press Ctrl+Shift+A (⇧⌘A for macOS), start typing Experimental features, select this command from the list, and press Enter. Then, enable the ruby.docker.internal.via.exec option and click OK.

To learn more about Docker, refer to our documentation:
https://www.jetbrains.com/help/ruby/2019.1/docker.html
https://www.jetbrains.com/help/ruby/2019.1/using-docker-as-a-remote-interpreter.html

We’ll highly appreciate it if you try new capabilities and let us know about any issues in the comments section. You can also submit an issue in YouTrack. Thank you!

Download RubyMine 2019.1 RC

As usual, check out our release notes for the full list of improvements inside this build.

Cheers,
Your RubyMine Team

Comments below can no longer be edited.

11 Responses to How to work with Docker/Docker Compose from RubyMine

  1. Mark says:

    August 17, 2019

    You have ALREADY moved all this stuff around by 2019.2.

    E.g. there is no “Docker” item under View/Tool Windows in the main menu.

    It is now buried under services.

    How about updating the article, and maybe putting it in the Help in the app (where searching for “Docker” comes up empty)??

    • Andrey Aksenov says:

      August 21, 2019

      Hi Mark, thank you for the suggestion. I’ve added a link to the Services tool window blog post that describes changes related to moving Docker stuff to Services.
      You can check the actual versions of Docker tutorials in our help:
      Using Docker Compose as a Remote Interpreter
      Using Docker as a Remote Interpreter

      and maybe putting it in the Help in the app (where searching for “Docker” comes up empty)??

      Do you mean Help in the main menu of RubyMine? For now, you can select Help | Help from the main menu and search through our help using the embedded search engine.

  2. Daniel Zajic says:

    August 21, 2019

    What does it mean when I get:
    “Can’t create Ruby SDK… com.github.dockerjava.api.exception.BadRequestException… OCI runtime create failed… permissions denied…unknown”

    I’m not sure what path I’m supposed to use for “Ruby or version manager path”.

  3. Daniel Zajic says:

    August 21, 2019

    (continued) What I’m trying to achieve is to be able to jump to the definition of bundled gems, which doesn’t work because the gems are only installed inside the container, not in the host filesystem. (I am mapping the app code itself into the container using a volume.)

  4. Mark says:

    November 11, 2019

    Suggestions on running RSpec in a Rails app with this setup?

    I.e. I can run

    dc run app rspec spec to run all of the tests in a terminal….

    ….but I want to be able to run individual tests within the IDE, etc. like I can when running rspec outside of docker.

    Thanks

    • Andrey Aksenov says:

      November 11, 2019

      Hi Mark

      After you’ve assigned Docker Compose as a remote interpreter, can you run tests from the Project view or editor as described in the topic below ?
      Run tests from the Project view
      Run tests from the editor

      • Mark says:

        November 13, 2019

        Andrey,

        After setting up Docker Compose as a remote interpreter, when I try running specs from Project view, I get the error:

        “Cannot find RSpec runner script for Remote: ruby-2.6.3-p62 SDK”

        • Andrey Aksenov says:

          November 15, 2019

          Could you check if the ‘rspec’ gem is present in the SDK? In the project tree, there is a node callded “External Libraries”. If it’s missing, try to retrieve gems from the container again:
          – open Settings | Languages & Frameworks | Ruby SDK and Gems
          – select your SDK and press the Synchronize gems and RubyMine helper files button (Sync)

  5. Mark Fraser says:

    November 26, 2019

    Hi Andrey,

    The RSpec gems (rspec-core, rspec-rails, etc.) are not in the list directly under the External Libraries node. They do show up in the gem folder if I open the first node inside the External Libraries node labeled ” docker-compose://(path)

    If this helps at all I am informed by RM when I open the project of missing gems. But gems are not missing, otherwise I would not be able to run the tests and the app from the terminal. So something may be wrong with my Docker setup in RM?

    When I do the Synchronize step you mentioned it appears to finish but does not change anything else as far as I can see.

    Thanks

Subscribe

Subscribe for updates