美文网首页
docker中安装postgresql问题记录

docker中安装postgresql问题记录

作者: nnnnxcj | 来源:发表于2022-05-06 11:38 被阅读0次

    sudo /usr/bin/postgresql-setup initdb

    Failed to get D-Bus connection: 不允许的操作
    failed to find PGDATA setting in postgresql.service
    

    vi /usr/bin/postgresql-setup
    错误原因是因为setup脚本中使用 systemctl show -p Environment ...获取 PGDATA/PGPORT 但是容器中不可以执行 systemctl

    vi /usr/lib/systemd/system/postgresql.service

    /usr/lib/systemd/system/postgresql.service

    修改成

    /usr/bin/postgresql-setup

    sudo /usr/bin/postgresql-setup initdb

    初始化完成

    PS:

    • 一般创建数据库容器最好直接使用官方提供的镜像,通过设置环境变量来控制用户名、密码、data目录等,直接用镜像启动。(个人理解容器初衷就想隔离进程,而这种存储的服务最好就不跟其他在一起,避免互相影响)
    • systemctl enable XXX 以及 service XXX start 都不能在docker中使用,会提示:Failed to get D-Bus connection: 不允许的操作。想在docker中启动服务 需要找到对应的 XX.service 文件,找到对应的命令来启动进程,例如:(执行时注意用户权限)/usr/lib/systemd/system/postgresql.service
    ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA}
    ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
    ExecStop=/usr/bin/pg_ctl stop -D ${PGDATA} -s -m fast
    ExecReload=/usr/bin/pg_ctl reload -D ${PGDATA} -s
    

    相关文章

      网友评论

          本文标题:docker中安装postgresql问题记录

          本文链接:https://www.haomeiwen.com/subject/hdwayrtx.html