当前位置: 首页 > 知识库问答 >
问题:

运行postgres容器获得超级用户密码错误?

单修德
2023-03-14

DockerFile:

FROM library/postgres
COPY init.sql /docker-entrypoint-initdb.d/

init.sql:

CREATE TABLE incident_disposition (
incident_disposition_code VARCHAR,
incident_disposition_code_description VARCHAR
);

据我所知,从图书馆。..从docker hub中拉出postgres图像,副本将我的init.sql脚本推入入口点,所以不需要大的dockerfile,对吗?

 docker build -t my_postgres_image .
docker run --name testing my_postgres_image --publish 8000:8080 --detach  -e POSTGRES_PASSWORD=postgres -d postgres

日志中的错误

Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.

       See PostgreSQL documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html

从评论中尝试:

docker container logs testing
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


Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

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.
waiting for server to start....2020-03-26 14:06:51.064 UTC [46] LOG:  starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2020-03-26 14:06:51.072 UTC [46] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-03-26 14:06:51.108 UTC [47] LOG:  database system was shut down at 2020-03-26 14:06:50 UTC
2020-03-26 14:06:51.119 UTC [46] LOG:  database system is ready to accept connections
 done
server started

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
CREATE TABLE


2020-03-26 14:06:51.231 UTC [46] LOG:  received fast shutdown request
waiting for server to shut down....2020-03-26 14:06:51.232 UTC [46] LOG:  aborting any active transactions
2020-03-26 14:06:51.233 UTC [46] LOG:  background worker "logical replication launcher" (PID 53) exited with exit code 1
2020-03-26 14:06:51.234 UTC [48] LOG:  shutting down
2020-03-26 14:06:51.290 UTC [46] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2020-03-26 14:06:51.345 UTC [1] LOG:  starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2020-03-26 14:06:51.345 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2020-03-26 14:06:51.345 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2020-03-26 14:06:51.361 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-03-26 14:06:51.387 UTC [64] LOG:  database system was shut down at 2020-03-26 14:06:51 UTC
2020-03-26 14:06:51.398 UTC [1] LOG:  database system is ready to accept connections
2020-03-26 14:07:27.715 UTC [72] ERROR:  relation "incident_disposition" does not exist at character 15
2020-03-26 14:07:27.715 UTC [72] STATEMENT:  select * from incident_disposition;

共有1个答案

许高峻
2023-03-14

除评论外

由于最近的docker Image的更新,postgres images不允许在没有密码的情况下从任何地方连接到DB。所以您需要指定用户名/密码

docker run-P 8000:8080-e postgres_password=postgres--name testing-d my_postgres_image

 类似资料:
  • 在postgres中,如何将现有用户更改为超级用户?由于各种原因,我不想删除现有用户。

  • 问题内容: 我正在尝试在具有结构的Django Docker容器中创建createsuperuser。 要在django中创建超级用户,我需要在django交互模式下运行它: 并且因为我想使其在结构脚本中运行,所以我发现 此 命令可以避免输入密码 然后,将其与 “ docker exec” 放在一起,以在我的django容器中运行 问题出在linux管道上,管道(|)在其左侧的所有内容(包括doc

  • 问题内容: 我正在尝试在具有结构的Django Docker容器中创建createsuperuser。 要在django中创建超级用户,我需要以django交互模式运行它: 并且因为我想使其在结构脚本中运行,所以我发现 此 命令可以避免输入密码 然后,将其与 “ docker exec” 放在一起,以在我的django容器中运行它 问题出在linux管道上,管道(|)在其左侧的所有内容(包括doc

  • 在我的Postgres服务器中,使用命令pg_createcluster监听端口5433创建了一个集群。要设置用户postgres的密码,我遵循以下步骤: 编辑文件nano/etc/postgresql/9.3//pg_hba.conf 改变线路 托管所有127.0.0.1/32 md5 按行 托管所有127.0.0.1/32信任 sudo-u postgres psql-h localhost-

  • 根据我在pg_hba.conf中读到的内容,我推断,为了确保我被提示输入postgres用户的密码,我应该将pg_hba.conf的前两个条目方法从当前的“对等”编辑为“密码”或“md5”,但如果这是错误的,我不想破坏东西。我的方向是正确的吗?还是遗漏了一些明显的东西? 无论如何,更多细节- 在debian上安装了postgres 9.4之后,我通过这样做更改了postg雷斯用户的密码- …并输入

  • 我安装了一个Postgres扩展(uncent),带有 现在我可以在sql中使用unacccent,但前提是我是Postgres用户。 如何使所有/其他用户都可以使用Postgres扩展 (使用Postgres 9.3.5在Ubuntu上安装Im,使用apt安装) postgres@ip-172-31-39-147:/home/ubuntu/code/jthinksearch/报告/src/mai