Jetbrains Rider External Tools example based on Docker
Tags: jetbrains, rider, docker, backenddevelopment
Published: 2024-05-20 20:32:44

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](https://www.jetbrains.com/help/rider/Settings_Tools_External_Tools.html#advanced_options)! 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/az91slkmzbideihmrpof.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cr411vm5yjmlw2jnxrbu.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u77owvihrw2sa2htyzl7.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/btq5wtk2corwg3qeaa4k.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gzg2brtivfpku54ltb17.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6gbr6bvnalza8pk5rlqh.png)

## Use macros for <path> specific commands
To start _compose_ file just by clicking on external tool button - create new External Tool like on the screenshot:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e6x1ksgzv3qk29b6o9bt.png)

The _Working directory_ set with macros:
```
$UnixSeparators($ProjectFileDir$/tests)$
```
(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16qgkrb0u54bm0vigklb.png)

With a macros you can defined unique path (for an 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!
- [External Tools Rider](https://www.jetbrains.com/help/rider/Settings_Tools_External_Tools.html#advanced_options)
- [Built-in IDE macros](https://www.jetbrains.com/help/rider/built-in-macros.html)
- [External Tools IDEA](https://www.jetbrains.com/help/idea/settings-tools-external-tools.html)
- [External Tools WebStorm](https://www.jetbrains.com/help/webstorm/configuring-third-party-tools.html)

### 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)
```
this script will stop all containers and remove it. This command can be executed from any directory.