How to work with Docker/Docker Compose from RubyMine
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:
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.
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.
Your RubyMine Team
Subscribe to Blog updates
RubyMine 2024.1 Early Access Program is Open!
The RubyMine 2024.1 Early Access Program has now started! In this blog post, we’ll share our plans for the upcoming release and the areas we’re currently focusing on. The first EAP build includes performance and usability improvements, bug fixes, and updates to RBS language support.Now, you c…
RubyMine: How To Accelerate Project Indexing?
Hello everyone! We're excited to share more tips and tricks to enhance your RubyMine experience. In September, our team attended the Euruko 2023 conference, where RubyMine developer Maxat Mansurov delivered a fascinating talk on project indexing. Indexing is a process that involves forming indexe…
RubyMine 2023.3 EAP Update
Hello everyone! We’re back with an update on the state of the 2023.3 Early Access Program. You can download the latest EAP build from our website, via the free Toolbox App, or by using snaps for Ubuntu. Here are the biggest highlights of this release: Performance improvements As we me…
The RubyMine 2023.3 Early Access Program Is Open!
Hello everyone, The third RubyMine Early Access Program of 2023 is underway! The key change in the first EAP build is an important indexing optimization. By refactoring our code base, we’ve doubled RubyMine’s indexing speed compared to v2023.1. This is particularly noticeable when working…