首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文档化PostgreSQL - psql连接被拒绝

文档化PostgreSQL - psql连接被拒绝
EN

Stack Overflow用户
提问于 2014-10-13 15:08:42
回答 5查看 56.1K关注 0票数 24

我正在和码头商玩,我想把一个邮政集装箱变成码头。

我正在跟踪官方的示例,但是我无法连接到使用psql运行的映像。

我创建了带有示例内容的Dockerfile。我从Dockerfile构建了一个图像,并为它指定了一个名称。然后运行PostgreSQL服务器容器(在前台)。

代码语言:javascript
复制
~/test » docker run --rm -P --name pg_test eg_postgresql                                                                                                       
2014-10-10 06:12:43 UTC LOG:  database system was interrupted; last known up at 2014-10-10 06:12:29 UTC
2014-10-10 06:12:43 UTC LOG:  database system was not properly shut down; automatic recovery in progress
2014-10-10 06:12:43 UTC LOG:  redo starts at 0/1782F68
2014-10-10 06:12:43 UTC LOG:  record with zero length at 0/1782FA8
2014-10-10 06:12:43 UTC LOG:  redo done at 0/1782F68
2014-10-10 06:12:43 UTC LOG:  last completed transaction was at log time 2014-10-10 06:12:29.2487+00
2014-10-10 06:12:43 UTC LOG:  database system is ready to accept connections
2014-10-10 06:12:43 UTC LOG:  autovacuum launcher started

然后我打开另一个航站楼,找出港口:

代码语言:javascript
复制
~/test » docker ps                                                                                                                                             
CONTAINER ID        IMAGE                  COMMAND                CREATED             STATUS              PORTS                     NAMES
aaedb0479139        eg_postgresql:latest   "/usr/lib/postgresql   3 days ago          Up 41 seconds       0.0.0.0:49154->5432/tcp   pg_test

所以我可以使用psql连接到实例。但我不能..。

代码语言:javascript
复制
~/test » psql -h localhost -p 49154 -d docker -U docker --password                                                                                             
Password for user docker:
psql: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 49154?
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 49154?
could not connect to server: Connection refused
    Is the server running on host "localhost" (fe80::1) and accepting
    TCP/IP connections on port 49154?

任何帮助都是非常感谢的。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2014-11-23 05:24:19

在我的mac上运行这个对我有用:

代码语言:javascript
复制
 $ boot2docker ip
 The VM's Host only interface IP address is: 192.168.59.103

然后按以下方式连接:

代码语言:javascript
复制
 $ psql -h 192.168.59.103 -p 49159 -d docker -U docker --password

这样做并不理想,但https://docs.docker.com/installation/mac/的说明表明,如果您想直接从mac连接,这是正确的解决方案。

票数 13
EN

Stack Overflow用户

发布于 2019-09-24 13:55:51

对于我来说,解决方案只是在连接字符串中使用host.docker.internal而不是localhost

https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/225

票数 38
EN

Stack Overflow用户

发布于 2014-10-13 16:13:10

如果将--发布选项添加到docker run命令中

代码语言:javascript
复制
docker run --rm -P --publish 127.0.0.1:5432:5432 --name pg_test eg_postgresql 

当您运行docker文件时,下面的内容就可以工作了(注意端口现在是5432)

代码语言:javascript
复制
psql -h localhost -p 5432 -d docker -U docker --password
票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26343178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档