gpt4 book ai didi

linux - DBeaver/PostgresQL 无法连接到远程 docker 容器

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:32 34 4
gpt4 key购买 nike

我正在尝试通过 DBeaver 访问 postgresql docker 容器,但我不知道如何让它工作。

运行 docker port db_1 返回:

5432/tcp -> 0.0.0.0:5432

所以端口应该对连接开放。

postgresql.conf 设置为

listen_addresses = '*'

运行 docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' db_1 返回

172.19.0.2

当尝试将数据库连接到 localhost/127.0.0.1/172.19.0.2/db_1 Dbeaver 日志返回这个:

2019-03-18 17:22:03.000 - Connect with 'jdbc:postgresql://db_1:5432/test' (postgres-jdbc-169919c23d5-77ac021a71307fee)
....
2019-03-18 17:22:14.815 - SSH INFO: SSH_MSG_SERVICE_ACCEPT received
2019-03-18 17:22:14.824 - SSH INFO: Authentications that can continue: password,keyboard-interactive
2019-03-18 17:22:14.825 - SSH INFO: Next authentication method: password
2019-03-18 17:22:18.432 - SSH INFO: Authentication succeeded (password).
2019-03-18 17:22:18.458 - Connection failed (postgres-jdbc-169919c23d5-77ac021a71307fee)
2019-03-18 17:22:18.459 - SSH INFO: Disconnecting from domain.com port 22
2019-03-18 17:22:18.461 - SSH INFO: Caught an exception, leaving main loop due to Socket closed
2019-03-18 17:22:18.514 - org.jkiss.dbeaver.model.exec.DBCConnectException: The connection attempt failed.
org.jkiss.dbeaver.model.exec.DBCConnectException: The connection attempt failed.
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.openConnection(JDBCDataSource.java:179)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.openConnection(PostgreDataSource.java:363)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.initializeRemoteInstance(PostgreDataSource.java:122)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.<init>(JDBCDataSource.java:100)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.<init>(JDBCDataSource.java:89)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.<init>(PostgreDataSource.java:80)
at org.jkiss.dbeaver.ext.postgresql.PostgreDataSourceProvider.openDataSource(PostgreDataSourceProvider.java:97)
at org.jkiss.dbeaver.registry.DataSourceDescriptor.connect(DataSourceDescriptor.java:770)
at org.jkiss.dbeaver.runtime.jobs.ConnectJob.run(ConnectJob.java:70)
at org.jkiss.dbeaver.ui.dialogs.connection.ConnectionWizard$ConnectionTester.run(ConnectionWizard.java:232)
at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:101)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.Driver$ConnectThread.getResult(Driver.java:405)
at org.postgresql.Driver.connect(Driver.java:263)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.lambda$0(JDBCDataSource.java:148)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.openConnection(JDBCDataSource.java:157)
... 11 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:140)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:109)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:67)
at org.postgresql.core.PGStream.receiveChar(PGStream.java:306)
at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:405)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:94)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454)
at org.postgresql.Driver.access$100(Driver.java:57)
at org.postgresql.Driver$ConnectThread.run(Driver.java:364)
at java.lang.Thread.run(Thread.java:748)

对于如何建立连接真的一无所知。 SSH 隧道显然有效,但与数据库的连接失败。我有一个在另一个容器中运行的 spring boot 应用程序,通过连接字符串 jdbc:postgresql://db_1:5432/test 连接它就像一个魅力。

对此有任何意见吗?难道 0.0.0.0 没有以某种方式映射到内部网络?

最佳答案

你究竟是如何运行你的容器的,我怀疑你可能没有公开端口?因为我只是尝试在 PS 中使用以下命令运行一个 postgres 实例:

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

将默认的 postgres 容器端口 5432 映射到我本地的 5433 端口(因为我在本地安装了 postgres,不想遇到某种端口干扰问题),后来通过访问 docker 和创建了一个数据库运行一些 psql 命令,如 this answer 中所述然后从 DBeaver 访问数据库

enter image description here

一切正常!希望这会有所帮助。

关于linux - DBeaver/PostgresQL 无法连接到远程 docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55226157/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com