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.
- Enable Docker support
- Work with images and containers
- Build new images and start services
- Use Docker/Docker Compose as a remote interpreter
- Docker support updates in v2019.1
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.
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 button in the Settings/Preferences dialog. RubyMine will automatically choose the required way to connect to Docker.
Click OK and then click the button in the Docker tool window to establish a connection to Docker and see the available images, containers, and services.
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.
In the context menu of specific entities, you can perform various actions, for example, start and stop containers, inspect their properties, and so on.
You can push images to the preconfigured Docker repository.
You can configure the registry settings in Settings/Preferences | Build, Execution, Deployment | Docker | Registry.
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.
Once the Dockerfile is ready, you can build an image from it. Click the button in the gutter and choose 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.
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.
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.
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.
After you’ve finished editing, start your services by clicking the docker-compose up button.
RubyMine then pulls/rebuilds required images and runs both services.
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.
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.
- Installing gems
In v2018.3 and older, you can install new gems by rebuilding the underlying Docker images.
With v2019.1, new gems can be quickly installed into a running container.
- 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!
As usual, check out our release notes for the full list of improvements inside this build.
Cheers,
Your RubyMine Team
Mark says:
August 17, 2019You 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, 2019Hi 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
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.
Daniel Zajic says:
August 21, 2019What 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”.
Andrey Vokin says:
August 22, 2019Looks like RubyMine can’t work via Docker Plugin API. We need more details like OS, Docker and docker-compose versions. Could you file an issue
https://youtrack.jetbrains.com/newIssue?project=RUBY&c=Assignee%20andrey.vokin&c=Subsystem%20Docker
Daniel Zajic says:
September 20, 2019It seems to be working now, on the latest version of RubyMine and Docker. Woohoo!
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.)
Mark says:
November 11, 2019Suggestions 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, 2019Hi 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, 2019Andrey,
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, 2019Could 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 (
Mark Fraser says:
November 26, 2019Hi 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