Skip to main content

Command Palette

Search for a command to run...

Build Phoenix Docker Compose development environment easily

Updated
2 min read

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.

https://qiita.com/koyo-miyamura/items/a609de2e9fadaf198243

https://zenn.dev/koga1020/articles/d260bc1bde8267

https://qiita.com/mnishiguchi/items/e367743bca3520e2a387

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

More from this blog

Raspberry Pi TensorFlow Liteで物体検出を楽しむ

この記事について Raspberry Pi、TensorFlow、Pythonのいずれにも詳しくない筆者が、物体検出をやって楽しんだ成果の記録です。 TensorFlow公式の物体検出のサンプルプログラムを実行します。 動作環境 ボード Raspberry Pi 4 Model B OS Raspberry Pi OS (32-bit または 64-bit) デスクトップ環境 カメラ Raspberry Pi カメラモジュール v2 Python Python ...

Apr 23, 20231 min read

Elixir Circuits.I2C with Mox

This is written in Japanese. I might convert it to English later, maybe. はじめに Elixirのテストでモックを用意するときに利用するElixirパッケージとして、moxが人気です。Elixir作者のJosé Valimさんが作ったからということもありますが、ただモックを用意するだけではなくElixirアプリの構成をより良くするためのアイデアにまで言及されているので、教科書のようなものと思っています。 一言でいうと「その場...

Dec 3, 20213 min read
M

Masatoshi Nishiguchi's Blog

62 posts