Learning Elixir - Elixir set up with docker tutorial
I just start learning Elixir, a functional language based on Erlang, recently. I usually don't like to install anything I am not familiar because I feel it will make my computer a mass. So, I go to docker again. Noted, this tutorial setup is only for learning and practice. Not sure if it is good for your production.
First use this command to run Elixir in docker.
docker run -it --name myElixir -v /YOUR/LOCAL/PATH:/YOUR/DOCKER/CONTAINER/PATH elixir
To understand this command, it
- Name the container to "myElixir".
- Mount a volume(learn more about docker volume, think about you make a share folder between docker container and your laptop).
- Run Elixir image.
Once you run the command, your terminal will put you into iex mode. You should be able to run some command here.
Erlang/OTP 19 [erts-8.3.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.4.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
There is a reason why I mount a volume here. It save your time to put script into container. You choose your script folder and share it with docker container. Say you have a hello script in volume folder.
hello.exs
IO.puts "Hello World!!!"
Now you can try execute script.
iex(1)> c "hello.exs"
Hello World!!!
[]
Now you want to modify hello.exs and to try more advance function. You need to do nothing for update script in docker container. Volume folder did it for you.
If you want to enter bash mode of container, do not do Ctrl+c
in your iex terminal. That will also terminate your Elixir container.
You could do following to enter bash.
- Open another terminal.
- Run
docker exec -it myElixir bash
, this will enter container with name "myElixir". - Now you are in bash and could also run your .exs script
root@23059812151f:/app# elixir hello.exs
Hello World!!!
Conclusion:
Using docker is a good idea to learn a new language. I use to have bad experience when learning Python.I was a beginner and I installed different version of Python and then mass up my laptop. With docker, it is fine to mass up. Because it all in Docker, if you don't need it anymore, just remove it! Amazing!
And now, I can enjoy my learning of Elixir.