メインで参考にしたサイト
Ruby 3.x, Rails 7.x, PostgreSQL の Docker 環境構築 2023 #Rails - Qiita
途中以下のエラーが発生
bash
$ docker compose run frontend rails db:create
[+] Creating 1/0
✔ Container free-market-app-backend-1 Running 0.0s
FATAL: could not open file "global/pg_filenode.map": Permission denied
Couldn't create 'myapp_development' database. Please check your configuration.
rails aborted!
ActiveRecord::ConnectionNotEstablished: FATAL: could not open file "global/pg_filenode.map": Permission denied (ActiveRecord::ConnectionNotEstablished)
Caused by:
PG::ConnectionBad: FATAL: could not open file "global/pg_filenode.map": Permission denied (PG::ConnectionBad)
Tasks: TOP => db:create
(See full trace by running task with --trace)
解決策
ホストマシン上で以下のコマンドを実行してtmo/dbの権限を付与して解決した
bash
# ホストマシン上で実行
sudo chown -R 1000:1000 ./tmp/db
sudo chmod -R 700 ./tmp/db