Programming in Elixir with Docker on Windows

What I have done is create a batch file in Windows, with the following contents:

wsl --user myusername --distribution Ubuntu --exec sudo service postgresql start

Then created a task in the “Task Scheduler” in Windows that starts when I log on to Windows. This ensures that when WSL is used, the postgres service is already started. As can be seen above this is for Ubuntu, but if you can manually start your service in your distribution in the console, this can be automated in the same manner as above.

Here the prerequisites for the above to work:

sudo visudo

Add the following to the end of the file:

%sudo ALL=(ALL) NOPASSWD: /usr/sbin/service postgresql *

I have documented my installation steps for Elixir/Erlang in Ubuntu on WSL here, in case you are interested:

1 Like

In general WSL can not really run services, be it through systemd or any other init system, as WSL does not run any init system.

Some WSL aware programs (like docker) install itself into separate WSL machines and then start a hidden session. They basically do what rudolfb describes.

Postgres is not WSL aware, but you can install postgres on windows and connect to it from your in-WSL application (WSL is transparently bridged to the hostnetwork).

I couldn’t find solution on OpenSUSE, so I tried both Alpine and Debian. I had some issues on Alpine, but Debian seems to be the best choice. Everything works out of the box and thanks to the backports repository, Debian ships with Elixir 1.10.3 and Postgres 13.3.