Build Phoenix Docker Compose development environment easily

I wrote a script called phx-docker-compose-new that can be used instead of mix 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.

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 ~/.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/

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


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.


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,, :registered_name) |> elem(1)}

To stop the app, use the following command.



Wrapping up

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