DEV Community

Nik Volkov
Nik Volkov

Posted on • Updated on

Jetbrains Rider External Tools example based on Docker

Hello!

In my work I often use Docker Compose to start test environment (databases, message buses, etc). Usually, I restart or remove containers and rerun it from docker-compose.yml file. In general, compose files stores in %SolutionDir%/tests/ directory. In my pet projects I organise project structure in the same way.

To stay focused on code and stop switching to Docker-dashboard (or type commands) I need functionality that will:

  • restart containers from IDE
  • remove containers from IDE
  • start compose file from IDE
  • show actual state for every container from IDE

I found a solution to achieve all these goals. This is the Rider External Tools! This feature allows you to start shell-scripts, external apps and something like that. I want to show you how I use these tools.

Create an External Tool

The easiest way to show you creation tool is script for containers state.
Open the Rider IDE. Go to Settings → Tools → External Tools and click on the + button.

Image description

Add a name and a description (optional) to a new tool. For example the name is Container stats. You can type a new group name to create a specific group of your tools. Choose Docker as program. Add ps -a as arguments to docker command. Click OK button to save a tool.

Congratulations! You have created your first External Tool!

Add new tool to a toolbar

External Tools will not be so useful if it can't be placed on a toolbar. It's very simple!
Open a context menu on the central toolbar (or any other).
And choose the Customize Toolbar... option.

Image description

In the opened menu choose Center toolbar and click the + button. Now you can add an External Tool as button on the toolbar or add a separator to divide groups of buttons.

Image description

To add your custom External Tool choose Add Action... → External Tools → %GroupName% → Container stats → OK. After that, choose your tool in list and click on the pencil button.Image description

Now you can upload your own image for button or choose Jetbrains standard icons. I just typed docker and chose a nice Docker logo.

Image description

All done! Let's test our new tool-button. Just click on it and you will see an output in Runner menu.

Image description

Use macros for specific commands

To start compose file just by clicking on external tool button - create new External Tool like on the screenshot:

Image description

The Working directory set with macros:

$UnixSeparators($ProjectFileDir$/tests)$
Enter fullscreen mode Exit fullscreen mode

(for mac/linux).
This macros will create absolute path to your project folder and concatenate /tests postfix.

Add the new tool to toolbar and run it. You will see command output in the runner window.

Image description

With macros you can defined unique path (for a External Tool it must be absolute path) for you tool.

Thank you! Hope this article will be helpful to you!

See also

External Tools available not only for Rider!

p.s.

You can create your own script and map it on a tool. For example:

docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)
Enter fullscreen mode Exit fullscreen mode

this script will stop all containers and remove it. This command can be executed from any directory.

Top comments (1)

Collapse
 
ameliacharellot profile image
amelia charlotte

Great article! Integrating Docker with Jetbrains Rider's External Tools is a game-changer for streamlining development workflows. By setting up Docker commands directly within the IDE, developers can manage containers, build images, and orchestrate their entire Docker environment without leaving Rider. This seamless integration not only enhances productivity but also ensures consistency across development and production environments. Looking forward to more tips on optimizing Docker usage in Rider!
-Hire App Developers in India