构建 Postgres 容器时修改用户密码出错

在容器中成功安装 PostgreSQL 后,启动脚本会尝试更改 discourse 用户的密码。但是,我收到了这个错误:

Pups::ExecError: su - postgres -c 'psql discourse' failed with return #<Process::Status: pid 100 exit 141>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"stdin"=>"alter user discourse with password 'redacted';\n", "cmd"=>"su - postgres -c 'psql discourse'", "raise_on_fail"=>true}
bootstrap failed with exit code 141
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.

看起来 PostgreSQL 在执行此命令时并未运行,因此在管道破裂时失败。我的 postgres.yml 是基于 data.yml 示例文件配置的,所以我不太确定我哪里做错了。有什么建议吗?

请您

然后在此处分享它们?

1 个赞

您好,之前的日志中没有明显问题,但在容器日志中我注意到此消息:

2024-01-26 12:30:54 I, [2024-01-26T17:30:54.465403 #1]  INFO -- : Reading from stdin
2024-01-26 12:30:54 /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/config.rb:22:in `block in initialize': undefined method `has_key?' for nil:NilClass (NoMethodError)
2024-01-26 12:30:54
2024-01-26 12:30:54         @config[key] = {} unless @config.has_key?(key)
2024-01-26 12:30:54                                         ^^^^^^^^^
2024-01-26 12:30:54     from /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/config.rb:21:in `each'
2024-01-26 12:30:54     from /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/config.rb:21:in `initialize'
2024-01-26 12:30:54     from /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/cli.rb:68:in `new'
2024-01-26 12:30:54     from /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/cli.rb:68:in `run'
2024-01-26 12:30:54     from /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/bin/pups:9:in `<top (required)>'
2024-01-26 12:30:54     from /usr/local/bin/pups:25:in `load'
2024-01-26 12:30:54     from /usr/local/bin/pups:25:in `<main>'

即使注释掉了 after_postgres 密码修改项,这也会导致容器崩溃,这就是出现管道破裂的原因。