Python连接基于docker运行的Postgres数据库
在docker中生成Postgres数据库服务
https://github.com/docker-library/postgres
参考上述链接,运行docker build构建postgres镜像
构建镜像,运行服务
- 参考下述链接,运行docker build构建postgres镜像
https://github.com/docker-library/postgres - 参考下述命令进入镜像
docker run -it -p 5432:5432 pstgres /bin/bash
- 参考下述命令,运行服务器
- 创建集群
pg_createcluster 11 main --start
- 修改配置(root角色)
修改/etc/postgresql 路径下 pg_hba.conf文件(使用find命令查找该文件具体位置),提前安装vim,
在下面配置处添加多一行配置,开放外部访问docker内数据库权限。
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
- 启动服务

本文介绍了如何在Docker中构建并运行Postgres数据库服务,包括构建镜像、运行服务、配置pg_hba.conf以允许外部访问,并提供Python连接数据库的测试步骤。
最低0.47元/天 解锁文章
5013

被折叠的 条评论
为什么被折叠?



