Example of a containerised Phoenix web server (app_starter_kit) with PostgreSQL database
Based off this helpful dev.to post blog post
- Install Elixir on your machine https://elixir-lang.org/install.html
- Install Phoenix
- creare .env file and populate with
DATABASE_URL=postgres://postgres:postgres@db:5432/postgres
-
- locate
/config/dev.exs
- change the IP address from
{127, 0, 0, 1}
to{0, 0, 0, 0}
in order to reach the phoenix server within docker container. - in same dev.exs file, locate
config :app_starter_kit, AppStarterKit.Repo
and removeusername: "", password: "", hostname: "", database: ""
and replace withurl: System.get_env("DATABASE_URL")
- locate
- run
docker compose up
- If
Postgrex.Protocol error
shows, rundocker-compose run web_app mix ecto.create
to initiate the DB connection between phoenix and db container
- Official website: https://www.phoenixframework.org/
- Guides: https://hexdocs.pm/phoenix/overview.html
- Docs: https://hexdocs.pm/phoenix
- Deployments: https://hexdocs.pm/phoenix/deployment.html
- Forum: https://elixirforum.com/c/phoenix-forum
- Source: https://github.com/phoenixframework/phoenix
To start your Phoenix server:
- Install dependencies with
mix deps.get
- Create and migrate your database with
mix ecto.setup
- Start Phoenix endpoint with
mix phx.server
or inside IEx withiex -S mix phx.server
Now you can visit localhost:4000
from your browser.