Build Phoenix Docker Compose development environment easily

I wrote a script called phx-docker-compose-new that can be used instead of mix phx.new to generate a new Phoenix application.

Building the development environment for a Phoenix application using Docker Compose is convenient because you can set up not only the application but also the PostgreSQL database, Livebook, etc. all at once.

However, the reality is that it is not always easy and requires some know-how.

qiita.com/koyo-miyamura/items/a609de2e9fada..

zenn.dev/koga1020/articles/d260bc1bde8267

qiita.com/mnishiguchi/items/e367743bca3520e..

I just thought it would be nice to have a script that allows us to easily build a Phoenix development environment using Docker Compose. Of course, just thinking about it won't change anything, so I got down to business straight away.

日本語版

Getting started

Make sure that Git, Docker, and Docker Compose are installed in your system.

git version
docker --version
docker compose version

Download the source code for the phx-docker-compose-new command.

git clone https://github.com/mnishiguchi/phx-docker-compose-new.git ~/.phx-docker-compose-new

Define an alias so you can use the phx-docker-compose-new command in your terminal.

alias phx-docker-compose-new=~/.phx-docker-compose-new/phx-docker-compose-new.sh

Generate a Phoenix sample app using the phx-docker-compose-new command. For available options, refer to Phoenix official documentation.

phx-docker-compose-new sample_phx_app --no-assets --no-gettext --no-mailer

Go into the generated app directory and launch the app.

cd sample_phx_app

bin/start

You can access the URLs below and start developing your Phoenix app right now!

docker-compose-demo 2023-11-23 09-44-06.png

You can look at the log with the command below. Press Ctrl + C to close the log.

bin/logs --follow

Elixir's interactive console (IEx) can be started with the following command.

bin/console

Since IEx is open, we might as well do something. Let's display a list of processes.

IEx.configure inspect: [limit: :infinity]

for pid <- Process.list, do: {pid, Process.info(pid, :registered_name) |> elem(1)}

To stop the app, use the following command.

bin/stop

:tada::tada::tada:

Wrapping up

Congratulations! Now you can build a Phoenix application development environment easily any time.

toukon-qiita-macbook_20230912_091808.jpg