【发布时间】:2018-01-22 16:10:27
【问题描述】:
我按照以下说明构建了一个 Rails 开发环境 https://docs.docker.com/compose/rails/
它可以工作,但我无法从主机连接到 Postgres 服务器。我正在运行 macOS High Sierra。当我运行 docker container ls 时,我看到 5432/tcp 作为 Postgres 容器的端口。请注意,5432 前面没有列出 IP。当我运行 docker network inspect <postgress_container_ID> 时,我得到 172.18.0.2 作为 IP。
但是当我运行psql -h 172.18.0.2 -p 5432 -U postgres 时,我得到了
xpsql: could not connect to server: Operation timed out
Is the server running on host "172.18.0.2" and accepting
TCP/IP connections on port 5432?
我做错了什么?
【问题讨论】:
-
如果你使用 5433:5432 它不会暴露 5433 端口,你会得到连接被拒绝。只要将其更改为“5433:5432”,它就会起作用。用官方的 postgres:13.2 镜像测试(也有 13 个)。
标签: postgresql docker rails-postgresql remote-connection