This repo contains simple boilerplate files that can be added to any Phoenix application so you may run it and its database inside Docker containers using Docker Compose.
- One-line dev environment setup:
docker-compose up
. This command creates the database, does the Dialyzer pre-work (if the project has Dialyxer installed), and everything else. - Developer-friendly setup: Source code is mounted so that changes in the container appear on the host and vice-versa.
- Fast re-builds because the
Dockerfile
is written to help Docker cache the images. - Syncing with Postgres startup delay.
- All the crappy little dependencies installed.
- No weird hacks.
Uses Elixir 1.9.4 (compatible with Phoenix 1.4), and latest Postgres.
- Copy the three files (
Dockerfile
,docker-compose.yml
, andrun.sh
) to an existing Phoenix project which you want to Dockerize. - Make
run.sh
executable, e.g.chmod +x run.sh
- Edit the database connection settings for the environments which will use this setup (usually
dev.exs
andtest.exs
). You can hard-code the credentials for the relevant environment(s) to reference the hostname ofdb
, a username ofpostgres
, and an empty password, or you can specify environment-variable overrides like the following:
# Inside config/dev.ex and/or config/test.exs
config :my_app, MyApp.Repo,
hostname: System.get_env("DB_HOST", "localhost"),
password: System.get_env("DB_PASS", "postgres"),
# ... etc...
- Spin it up with
docker-compose up
.
Tests can be run in the container like so:
docker-compose run web mix test
Or, for a slightly faster startup time,
docker-compose exec web mix test
... I haven't found a disadvantage of re-using the running container this way.