This is a setup for local dev environments for elixir. The aim is to have a repeatable process for setting up and developing on new elixir projects independently of the local machine.
- Docker
For local development, I create a docker image called elixir-env
from the Dockerfile
in this repo. All the work I do I do it from an interative terminal in this docker container. This means that I know that I can land on any machine that has docker and get going with writing elixir code.
In this repo are two files: a Dockerfile
and a docker-compose.yml
file. To create a new phoenix project you take the following steps:
-
Clone this repo.
-
docker build . -t elixir-env
- this creates an image from the Dockerfile that has elixir and phoenix installed on it. This will be our default environment for both building new projects and working on those projects (e.g. iniex
). -
Change directory to wherever you want to create your new project and run
docker run --interactive --tty --rm --volume $(pwd):/app elixir-env
- this drops you onto a command prompt on that container. -
Depending on what kind of project you are creating, run the following:
-
Phoenix:
mix phx.new new_project --app new_project --no-webpack
- this creates thenew_project
phoenix project (I'm a fan of--no-webpack
). -
Mix:
mix new new_project
-
-
exit
the container - you will have a fullnew_project
directory. Probably time for agit init
.
For mix based projects, we can then start an iex session by:
-
In our
new_project
directory, rundocker run --interactive --tty --rm --volume $(pwd):/app elixir-env
. I've made this part of aMakefile
so that it is easier to remember. -
iex -S mix
ormix test
etc, depending on what you want to do.
-
For
Phoenix
projects, copy thedocker-compose.yml
file from from this repo to the new project you have created. -
docker compose build
- to build the images that docker compose will use. This will include a web image and a postgres image. -
Edit the
dev.exs
config in the phoenix app so that the settings match those for postgres. KEY POINT: you need to change thehost
declaration fromlocalhost
todb
for docker networking to work. -
docker compose up
- will start the phoenix app and the postgres container and all being well, you can start development. Phoenix will be running onlocalhost:4000
. -
docker run --interactive --tty --rm --volume $(pwd):/app elixir-env
will give you an elixir environment where you can run mix tasks or aniex
session.`
Change the default postgres user/password/database on app creation
FIX: I need to include that package that lets you do hot reloads on Linux\n"