Early Access Program Features Learn RubyMine Tutorials

How to work with Docker/Docker Compose from RubyMine

To get the most recent information about Docker support in RubyMine, refer to our documentation:
Tutorial: Docker Compose as a remote interpreter
Tutorial: Docker as a remote interpreter

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:

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

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.

Your RubyMine Team

image description