从同一台物理机上访问在docker上运行的PostgreSQL

时间:2017-10-09 06:50:49

标签: postgresql docker

我是docker的新手,下面是启动postgreSQL的Dockerfile部分:

docker run -p 5432:4006 c00d99a4b93e

我使用命令

运行docker
$ docker run -p 8080:4005 -p 5432:4006 c00d99a4b93e
2017-10-09 06:36:03.547 UTC [5] LOG:  database system was interrupted; last known up at 2017-10-09 06:24:12 UTC
2017-10-09 06:36:03.586 UTC [5] LOG:  database system was not properly shut down; automatic recovery in progress
2017-10-09 06:36:03.587 UTC [5] LOG:  redo starts at 0/1784DA8
2017-10-09 06:36:03.587 UTC [5] LOG:  record with zero length at 0/1784DE8
2017-10-09 06:36:03.587 UTC [5] LOG:  redo done at 0/1784DA8
2017-10-09 06:36:03.587 UTC [5] LOG:  last completed transaction was at log time 2017-10-09 06:24:12.415859+00
2017-10-09 06:36:03.592 UTC [5] LOG:  MultiXact member wraparound protections are now enabled
2017-10-09 06:36:03.596 UTC [1] LOG:  database system is ready to accept connections
2017-10-09 06:36:03.602 UTC [9] LOG:  autovacuum launcher started

启动Docker后记录:

$  docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                          NAMES
72191e69bf5a        c00d99a4b93e        "/usr/lib/postgresql/"   39 seconds ago      Up 37 seconds       5432/tcp, 8009/tcp, 8080/tcp, 0.0.0.0:8080->4005/tcp, 0.0.0.0:5432->4006/tcp   modest_lalande

我正在尝试使用pgAdmin从本地计算机上查看此数据库。

我试图连接到: 0.0.0.0:4006 127.0.0.1:4006

但我收到连接拒绝例外。

这是Docker ps输出

{{1}}

你能帮助我做错了吗?

1 个答案:

答案 0 :(得分:1)

这些应该倒置:

-p 8080:4005 -p 5432:4006

对此:

 -p 4005:8080 -p 4006:5432

此外,如果您在带有docker工具箱的Windows上使用docker,则该机器的ip将不同(默认情况下为192.168.99.100而不是localhost)