【问题标题】:How to use centos:8 docker image run postgresql client? [closed]如何使用 centos:8 docker image 运行 postgresql 客户端? [关闭]
【发布时间】:2021-07-04 00:48:10
【问题描述】:

在一个 centos 8 Dockerfile 中

FROM centos:8

RUN yum update -y && yum install -y openssh-server sudo && yum clean all
RUN rm -rf /run/nologin

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

启动后,在容器中安装postgresql客户端

docker exec -it centos8 /bin/bash

dnf module enable postgresql:12
dnf install postgresql-server
postgresql-setup --initdb

出错了

[root@centos8 /]# postgresql-setup --initdb
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
FATAL: no db datadir (PGDATA) configured for 'postgresql.service' unit

查看状态

[root@centos8 /]# systemctl status postgresql
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

当运行psql

[root@centos8 /]# psql
psql: error: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

为什么不能使用systemctl服务?如何在上面安装 Postgres 客户端?

【问题讨论】:

  • 这个设置听起来像是在尝试手动配置虚拟机,但在 Docker 容器中的交互式 shell 中。这不是 Docker 的典型用法,尤其是因为一旦容器退出,您安装的任何内容都会丢失。这也不是一个真正的编程问题,而更像是一个 Linux 工具问题。 help center 描述了 Stack Overflow 上允许的主题。

标签: postgresql docker centos8


【解决方案1】:

Systemd 在 docker 容器中不受支持。所以如果你想启动postgresql server服务,你必须直接通过执行postgresql二进制来启动它,就像how official do一样,也指它的Dockerfile

exec gosu postgres "$BASH_SOURCE" "$@"

但是,你接下来提到了:

如何在上面安装 Postgres 客户端?

所以,如果你只是想安装postgres客户端,你已经完成了:psql是postgres客户端,不需要启动postgresql服务器:

[root@4234406b3e6c /]# psql --help
psql is the PostgreSQL interactive terminal.

【讨论】:

  • 我在安装后尝试运行psql,更新我的问题时出现错误。 When run psql 部分。
  • 当然,postgresql服务器没有启动,所以你的客户端无法链接到服务器。这不是客户端问题,这是您的服务器问题。您的问题提到您需要一个客户端,所以客户端没问题,您可以使用此客户端连接到外部 postgresql 服务器以验证您的客户端是否正常。
  • 你的意思是在centos容器上运行命令吗?我试过并返回:bash: exec: gosu: not found.
  • 我现在明白了。谢谢你。如果我通过psql [host] 连接到远程服务器应该可以工作。
猜你喜欢
  • 2011-07-03
  • 2021-01-23
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
  • 2010-09-11
  • 2013-11-11
  • 2021-04-24
  • 1970-01-01
相关资源
最近更新 更多