我正在尝试通过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
没有以某种方式映射到内部网络吗?