docker compose第一次运行时忽略了docker入口点initdb.d/*文件



我试图在docker compose中设置一个Postgresql数据库,它在一段时间内如预期那样工作。但现在,我的迁移sql脚本不再运行,即使在新的构建(sudo docker-compose buildsudo docker-compose up --build(和删除本地创建的持久卷(sudo rm -rf db-data(之后也是如此。

$ sudo docker-compose up
[+] Running 14/14
⠿ db Pulled                                                                                                                                                                                        10.7s
⠿ a2abf6c4d29d Pull complete                                                                                                                                                                      2.6s
⠿ e1769f49f910 Pull complete                                                                                                                                                                      2.8s
⠿ 33a59cfee47c Pull complete                                                                                                                                                                      2.9s
⠿ 461b2090c345 Pull complete                                                                                                                                                                      3.1s
⠿ 8ed8ab6290ac Pull complete                                                                                                                                                                      3.4s
⠿ 495e42c822a0 Pull complete                                                                                                                                                                      3.5s
⠿ 18e858c71c58 Pull complete                                                                                                                                                                      3.6s
⠿ 594792c80d5f Pull complete                                                                                                                                                                      3.7s
⠿ 794976979956 Pull complete                                                                                                                                                                      8.2s
⠿ eb5e1a73c3ca Pull complete                                                                                                                                                                      8.3s
⠿ 6d6360292cba Pull complete                                                                                                                                                                      8.3s
⠿ 131e916e1a28 Pull complete                                                                                                                                                                      8.4s
⠿ 757a73507e2e Pull complete                                                                                                                                                                      8.5s
[+] Running 2/2
⠿ Container db-1   Created                                                                                                                                                       0.2s
⠿ Container app-1  Created                                                                                                                                                       0.1s
Attaching to app-1, 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 ... Etc/UTC
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 ... 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   | 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   | waiting for server to start....2022-01-26 14:57:29.498 UTC [49] LOG:  starting PostgreSQL 14.1 (Debian 14.1-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-01-26 14:57:29.506 UTC [49] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db-1   | 2022-01-26 14:57:29.529 UTC [50] LOG:  database system was shut down at 2022-01-26 14:57:29 UTC
db-1   | 2022-01-26 14:57:29.542 UTC [49] 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/00000000000000_diesel_initial_setup
db-1   | 
db-1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/2021-10-21-140200_initial_schemes
db-1   | 
db-1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/2022-01-24-120647_fill_tables
db-1   | 
db-1   | waiting for server to shut down...2022-01-26 14:57:29.858 UTC [49] LOG:  received fast shutdown request
db-1   | .2022-01-26 14:57:29.865 UTC [49] LOG:  aborting any active transactions
db-1   | 2022-01-26 14:57:29.868 UTC [49] LOG:  background worker "logical replication launcher" (PID 56) exited with exit code 1
db-1   | 2022-01-26 14:57:29.868 UTC [51] LOG:  shutting down
db-1   | 2022-01-26 14:57:29.914 UTC [49] 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-01-26 14:57:29.993 UTC [1] LOG:  starting PostgreSQL 14.1 (Debian 14.1-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-01-26 14:57:29.994 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db-1   | 2022-01-26 14:57:29.994 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db-1   | 2022-01-26 14:57:30.008 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db-1   | 2022-01-26 14:57:30.026 UTC [63] LOG:  database system was shut down at 2022-01-26 14:57:29 UTC
db-1   | 2022-01-26 14:57:30.038 UTC [1] LOG:  database system is ready to accept connections

正如您所看到的,我的docker入口点initdb.d/*文件都被忽略了。请注意,我的3个迁移脚本在本地pg实例上运行良好。

我的docker作文看起来像这样:

version: '3.7'
services:
db:
image: postgres
restart: always
environment:
- POSTGRES_USER=***
- POSTGRES_PASSWORD=***
- POSTGRES_DB=***
ports:
- '5433:5432'
volumes: 
- ./db-data:/var/lib/postgresql/data
- ./migrations:/docker-entrypoint-initdb.d/ # copy the sql migrations
[...]
volumes:
db-data:

根据poatgres,图像入口点仅在执行的文件类型以下:

  • *.sh
  • *.sql
  • *.sql.gz
  • *.sql.xz

最新更新