【问题标题】:cannot connect to "postgres". The connection attempt failed无法连接到 \"postgres\"。连接尝试失败
【发布时间】:2023-01-11 18:30:01
【问题描述】:

我有一个在 docker 容器中运行的 postgres 数据库。我可以使用 pgadmin 连接到 postgres 服务器。但是,当我尝试使用 IntelliJ 连接到数据库时,出现错误:

“无法连接到“postgres”。连接尝试失败”

下面是使用 pgadmin 的连接信息:

主机名:postgres

用户名:postgres

密码:postgres

端口:5432

数据库:SpringDevDB

当我使用 Intellij 尝试相同的信息时,出现上述错误。

【问题讨论】:

标签: postgresql docker intellij-idea spring-jdbc


【解决方案1】:

pgadmin 是否托管在 Docker 中?

如果是,那么您可以尝试独立的 pgadmin 是否可以连接到它。

这可能是由于 Docker 容器中的安全原因,默认情况下没有网络端口会从 docker 实例本身暴露给客户端。所以尝试添加一个 -p 标志来暴露它,看看它是否有效:

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres -p 5432:5432

【讨论】:

    猜你喜欢
    • 2021-05-25
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 2013-03-26
    • 1970-01-01
    相关资源
    最近更新 更多