フォルダー構成は下記のようになっております。
docker-compose.yml
backend - sql/docker-entrypoint-initdb.d/00-neumann-init.sql
docker-compose.ymlの中身
version: '3'
services:
db:
image: postgres:14.3
environment:
POSTGRES_USER: neumann
POSTGRES_PASSWORD: password
POSTGRES_DB: neumann_development
TZ: Asia/Tokyo
ports:
- '5432:5432'
# stopでコンテナを落とすならDBのデータは消えないそうなのであえて永続化しない
volumes:
- ./backend/sql:/docker-entrypoint-initdb.d
00-neumann-init.sqlの中身
create user neumann2;
create database neumann_development2;
alter role neumann2 with Superuser;
これで docker-compose up --build
を実行しても下記のようなログが出力されてsqlが上手く実行されないです。
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/docker-entrypoint-initdb.d
ログ全体
Creating neumann_db_1 ... done
Attaching to neumann_db_1
db_1 | The files belonging to this database system will be owned by user "postgres".
db_1 | This user must also own the server process.
db_1 |
db_1 | The database cluster will be initialized with locale "en_US.utf8".
db_1 | The default database encoding has accordingly been set to "UTF8".
db_1 | The default text search configuration will be set to "english".
db_1 |
db_1 | Data page checksums are disabled.
db_1 |
db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1 | creating subdirectories ... ok
db_1 | selecting dynamic shared memory implementation ... posix
db_1 | selecting default max_connections ... 100
db_1 | selecting default shared_buffers ... 128MB
db_1 | selecting default time zone ... Asia/Tokyo
db_1 | creating configuration files ... ok
db_1 | running bootstrap script ... ok
db_1 | performing post-bootstrap initialization ... ok
db_1 | syncing data to disk ... initdb: warning: enabling "trust" authentication for local connections
db_1 | You can change this by editing pg_hba.conf or using the option -A, or
db_1 | --auth-local and --auth-host, the next time you run initdb.
db_1 | ok
db_1 |
db_1 |
db_1 | Success. You can now start the database server using:
db_1 |
db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1 |
db_1 | waiting for server to start....2022-06-04 13:45:32.867 JST [48] LOG: starting PostgreSQL 14.3 (Debian 14.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
db_1 | 2022-06-04 13:45:32.870 JST [48] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2022-06-04 13:45:32.879 JST [49] LOG: database system was shut down at 2022-06-04 13:45:32 JST
db_1 | 2022-06-04 13:45:32.886 JST [48] LOG: database system is ready to accept connections
db_1 | done
db_1 | server started
db_1 | CREATE DATABASE
db_1 |
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/docker-entrypoint-initdb.d
db_1 |
db_1 | 2022-06-04 13:45:33.259 JST [48] LOG: received fast shutdown request
db_1 | waiting for server to shut down....2022-06-04 13:45:33.262 JST [48] LOG: aborting any active transactions
db_1 | 2022-06-04 13:45:33.268 JST [48] LOG: background worker "logical replication launcher" (PID 55) exited with exit code 1
db_1 | 2022-06-04 13:45:33.269 JST [50] LOG: shutting down
db_1 | 2022-06-04 13:45:33.291 JST [48] LOG: database system is shut down
db_1 | done
db_1 | server stopped
db_1 |
db_1 | PostgreSQL init process complete; ready for start up.
db_1 |
db_1 | 2022-06-04 13:45:33.388 JST [1] LOG: starting PostgreSQL 14.3 (Debian 14.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
db_1 | 2022-06-04 13:45:33.389 JST [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2022-06-04 13:45:33.389 JST [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2022-06-04 13:45:33.393 JST [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2022-06-04 13:45:33.399 JST [62] LOG: database system was shut down at 2022-06-04 13:45:33 JST
db_1 | 2022-06-04 13:45:33.408 JST [1] LOG: database system is ready to accept connections
^CGracefully stopping... (press Ctrl+C again to force)
Killing neumann_db_1 ... done
ERROR: 2
他に必要な情報があればコメント頂ければと思います。
宜しくお願い致します。