6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

闘魂Phoenix道場:PostgreSQLをDockerで立ち上げるッ!!!(devcontainer付き) Phoenixアプリから使わせていただく

Last updated at Posted at 2025-06-18

いよいよはじまりました!
Qiita Tech Festa :tada::tada::tada:

はじめに

こんにちは、ElixirとPhoenixをこよなく愛する闘魂プログラマーです。
つまりAIプログラマーです。あっ、AIとは、Antonio Inokiさん、つまり猪木さんのことです。

本記事は、みんなでPostgreSQLの知見を共有しよう への参加記事です。

PhoenixのデフォルトDBはPostgreSQL

Phoenix では、プロジェクトを作成する際にPostgreSQLがデフォルトで使われます。

mix phx.new hello
# => デフォルトでPostgreSQLが選ばれます

Phoenixとは、Elixir製のすんごいWebアプリケーションフレームワークのことです。

DockerでPostgreSQLを立ち上げる

新しいPCを新調するたびに、自分のローカルにPostgreSQLを入れるのは面倒ですし、慎重派の私はDockerコンテナで立ち上げています。

docker run -d --rm -p 5432:5432 -e POSTGRES_USER=postgres  \
-e POSTGRES_PASSWORD=postgres postgres

POSTGRES_USERPOSTGRES_PASSWORDには、config/dev.exsにデータベースへの接続情報が以下のように作られるのでそれにあわせて、postgresをセットしています。

config/dev.exs
config :hello, Hello.Repo,
  username: "postgres",
  password: "postgres",
  hostname: "localhost",
  database: "hello_dev",
  stacktrace: true,
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

devcontainerでも起動してます

私がメンテしている phx_devcontainer というdevcontainer定義でもPostgreSQLが入っています。

こちらを使うと、Elixir + Phoenix + PostgreSQL の開発環境が短時間で整います。
devcontainerですので、つまりは所謂ひとつのCodespaceでも開発ができます。
別記事で紹介していますので、よければご覧ください。

おわりに

PhoenixとPostgreSQLは、最初から相性がいいです。意識しなくてもPostgreSQLと共に開発が始まります。

PostgreSQLキャンペーンをきっかけに、象さんのアイコンを思い出しました。

闘魂とは、己に打ち克つこと。そしてPhoenixアプリケーションの裏にPostgreSQLあり。

元氣ですかーーーッ!!!

6
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?