DEV Community

Cover image for Dockerizing Phoenix Development (6) Installing Phoenix
Alastair Measures
Alastair Measures

Posted on • Updated on

Dockerizing Phoenix Development (6) Installing Phoenix

The database is on tap, the elixir image is ready and sharp observers, on their third espresso, will notice: Phoenix is still not present!

To get Phoenix installed we need to:

  • have the containers running
  • sign in to the web container as devuser
  • install the Erlang and Elixir package managers
  • install the Phoenix package (and dependencies).

These things go into hidden folders within the (container) /apps folder because it is the home folder for the devuser account used for development.

  • After this, the standard mix commands can be used to initiate projects, run migrations, run the web servers and so on.
  • From this point, the standard text books for Phoenix 1.5 (e.g. McCord, Tate & Valim) can be followed without problems.

Installing

Start the containers:

From the command line:

docker-compose  up  -d
Enter fullscreen mode Exit fullscreen mode

Connect to the web container shell

From the command line:

docker exec  -u devuser  -ti  myp_dev_web_1  /bin/ash
Enter fullscreen mode Exit fullscreen mode

Install Erlang package manager called Rebar

mix local.rebar --force
Enter fullscreen mode Exit fullscreen mode

Install Elixir package manager called Hex

mix local.hex --force
Enter fullscreen mode Exit fullscreen mode

Install Phoenix tool packages

mix archive.install hex phx_new 1.6.10 --force
Enter fullscreen mode Exit fullscreen mode

Run up a fresh Phoenix project

mix phx.new myp
Enter fullscreen mode Exit fullscreen mode

All being well, your project is now rolling and you will need to adjust the database configuration for the project.

  • The database configuration should reflect the database user (myp_user) and database instance (myp_dev) created earlier.
  • The database configuration should also reflect that the database host should be db (the service name from the docker-compose.yml file) rather than localhost!

The Elixir driver for PostgreSQL is postgrex and there are some relevant extensions to consider at this point:

Remarks

  • This tutorial has been run through to test that it works. Any problems, leave a comment and I will respond.
  • This tutorial works through a few awkward challenges; these solutions may have saved you some time. If you are feeling generous, you could buy me a coffee!

Top comments (0)