Docker postgres 容器退出,错误代码为 1,没有错误消息
Docker postgres container exits with error code 1 without error message
当我尝试构建和 运行 我的 postgres 容器时,它立即退出并显示错误代码 1。这是自 Docker 更新到版本 4.7.0 以来发生的。我查看了日志,没有任何错误消息:
Creating football_marketplace-development_postgres_run ... done
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2022-04-10 03:22:59.257 UTC [35] LOG: starting PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-04-10 03:22:59.258 UTC [35] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-04-10 03:22:59.262 UTC [36] LOG: database system was shut down at 2022-04-10 03:22:59 UTC
2022-04-10 03:22:59.265 UTC [35] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/marketplace.sql
The input is a PostgreSQL custom-format dump.
Use the pg_restore command-line client to restore this dump to a database.
正如我们所见,没有错误消息,输出看起来和更新前一样正常。但由于某种原因它只是退出。
更奇怪的是,当我在容器退出后重新启动容器时,它不再退出并且运行良好。但我想让它不退出,这样我就不必总是重新启动它。
端口已释放。
我已经在此处查看过类似的线程,但它们都与一些错误消息相关联。
这是我的Docker文件:
FROM postgres
ADD ./marketplace.sql /docker-entrypoint-initdb.d
USER postgres
正如@Hans Kilian 指出的那样,问题是我导出的 sql 文件格式错误:custom-format 而不是普通格式。
解决方案是:将 sql 转储导出为普通文件。
当我尝试构建和 运行 我的 postgres 容器时,它立即退出并显示错误代码 1。这是自 Docker 更新到版本 4.7.0 以来发生的。我查看了日志,没有任何错误消息:
Creating football_marketplace-development_postgres_run ... done
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2022-04-10 03:22:59.257 UTC [35] LOG: starting PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-04-10 03:22:59.258 UTC [35] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-04-10 03:22:59.262 UTC [36] LOG: database system was shut down at 2022-04-10 03:22:59 UTC
2022-04-10 03:22:59.265 UTC [35] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/marketplace.sql
The input is a PostgreSQL custom-format dump.
Use the pg_restore command-line client to restore this dump to a database.
正如我们所见,没有错误消息,输出看起来和更新前一样正常。但由于某种原因它只是退出。
更奇怪的是,当我在容器退出后重新启动容器时,它不再退出并且运行良好。但我想让它不退出,这样我就不必总是重新启动它。 端口已释放。
我已经在此处查看过类似的线程,但它们都与一些错误消息相关联。
这是我的Docker文件:
FROM postgres
ADD ./marketplace.sql /docker-entrypoint-initdb.d
USER postgres
正如@Hans Kilian 指出的那样,问题是我导出的 sql 文件格式错误:custom-format 而不是普通格式。
解决方案是:将 sql 转储导出为普通文件。