A simple introduction to developing Elixir on Windows with Docker

I’m a Linux user myself, but having seen a lengthy thread about developing Elixir on Windows (and its problems), I decided to write a short blogpost for showing how to keep things simple and trouble-free. It mainly aims to programmers who don’t have Elixir experience yet, but want to give it a try without going through the whole setup.

First of all, if you don’t have Chocolatey yet: You want it, so get it from chocolatey.org.

Now you can install Visual Studio Code and Docker Desktop using chocolatey, just type this into a cmd running as admin:

choco install vscode
choco install docker-desktop

Of course you could install manually, but why should one wanna do that? 😉

Start Docker Desktop, register and login.

Now fire up vscode and install the extension ElixirLS Fork

Open the terminal (View => Terminal) and execute this command in the terminal:

docker pull elixir 

It will download the latest official Elixir docker image.

Elixir hast an interactive shell, which will launch by default when running the docker image:

docker run -it --rm elixir 

With this you can already try out simple things, and get started with the official getting started guide

But of course we also want to compile things, so now create a file “helloworld.ex” (yes yes, I know, boring example 🙂 )
As it’s elixirs nature, it doesn’t need a lot of code, just these 5 lines:

defmodule Hello do
   def world do
     IO.puts "Hello World!"

Now for the fun part: First enter this into the terminal:

docker run -it --rm -w /usr/src/app -v ${pwd}:/usr/src/app elixir elixirc helloworld.ex 

This will mount your current working directory into the docker image, where the helloworld.ex is compiled with elixirc. After the execution finished, you’ve got a new file Elixir.Hello.beam, which you can run with the following command:

docker run -it --rm -w /usr/src/app -v ${pwd}:/usr/src/app elixir elixir -e Hello.world

And that’s it. You’re ready to enjoy this beautiful, well thought language 🙂
If you’re into webapps: In my next post I’m showing how to create a Phoenix app using Docker.

1 Reply to “A simple introduction to developing Elixir on Windows with Docker”

  1. Refreshingly nice little article 😎 – straightforward and simple; thx!
    one remarks thou: installing vscode and docker can be done in one command: „choco install vscode docker-desktop -y“ (the „-y“ accepts all licenses).

Leave a Reply

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