Convenient management of test environments in docker-compose

Hello everyone, I want to tell you about my utility dcw (Docker Compose Workspace) for convenient management of test environments based on docker-compose.

I'll tell you a little about the problem that I tried to solve. I am a developer, including developing backends in different languages ​​and stacks. It so happens that I have many projects that I am developing or supporting. Probably many people have a similar story.

I have a problem with switching between projects, which can happen quite often, even several times a day. Was it like before without Docker? All the necessary software was installed on the developer’s machine, databases Postgres, Redis, some auxiliary services such as Keycloak, Apache PHP, Java… Perhaps each service or development language is also represented by several different versions. In general, the operating system couldn’t handle such a zoo normally for a long time and as a result, something conflicted with something else, something still broke somewhere and we had to reinstall everything again and deal with it. Overall it was hell.

It’s so good that now there is Docker and we can run all the necessary services, languages, etc. in it. You can use docker-compose to describe a test dev environment; this makes life even easier in terms of starting and stopping.

Moreover, for example, VSCode supports Dev Containers and can do all the work for us to start and stop the dev environment. But unfortunately, this does not completely save, since there are other IDEs that do not have such support.

Therefore, I settled on the fact that in every project I have a folder with docker-compose.yml, which picks up all the necessary additional services for local development and manually starts and stops it. However, there are some inconveniences here: each time you have to look at which environment is running from other projects, and if this is not the environment that is currently needed, then go to the folder with docker-compose.yml in another project, stop, and then go to the folder of the required project, look there docker-compose.yml and launch.

A lot of manual work, a lot of switching between projects. Having suffered a little, I wrote myself simple bash scripts that remembered the current docker-compose.yml, then stopped it and started a new one. The scripts were in ~/bin and looked something like this: switch_to_some_project, switch_to_another_project

And now the time has come and I decided to do it humanely, so the utility appeared dcw (https://github.com/navrocky/dcw).

It is written in C++, compiled statically with uClibc runtime, works without rebuilding on all possible Linux systems (x86, x86_64), also works in docker from scratch (I don’t really know why, but it works). Installed by simply copying the binary to /usr/local/bin or in ~/bin. If you are interested in how to build such static binaries, you can look into the Docker file Dockerfile.uclibc.

Allows you to add docker-compose.yml files to your local database, assign an alias and then quickly switch between them using this alias. There is autocompletion for bash, so it is not necessary to enter the entire commands and aliases, just click the tab.

Working with the utility

Working with the utility

I would like to add it to popular distributions, but it’s somehow complicated there, I haven’t implemented this idea yet. If someone writes in the comments how you can add your own package, for example, in Ubuntu, I would be very grateful.

I really hope that this utility will be useful to someone. Thank you for your attention.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *