无法从ubuntu上的docker-compose连接到Postgres

时间:2019-06-25 14:27:34

标签: postgresql docker docker-compose digital-ocean

我正尝试从docker-compose.yml文件连接到在数字海洋上托管的Ubuntu 18.04上运行的postgres数据库。 .yml文件包含以下内容:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.32
    restart: always
    ports:
      - '4466:4466'
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: postgres
            host: droplet-ip
            database: my-database
            user: my-user
            password: my-password
            rawAccess: false
            port: 5432
            migrations: true

我尝试使用“ localhost”,“ 127.0.0.1”和“ host.docker.internal”作为主机,但没有一个起作用。我已经将pg_hba.conf配置为侦听范围127.0.0.1/16和postgresql.conf的listen_address ='*'。尝试连接时,我从postgres获取以下日志:

No log level set, defaulting to INFO.
[INFO] {} - Started.
Jun 25, 2019 2:10:40 PM org.postgresql.core.v3.ConnectionFactoryImpl log
WARNING: IOException occurred while connecting to droplet-ip:5432
java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:69)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:156)
    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:452)
    at org.postgresql.Driver.connect(Driver.java:254)
    at slick.jdbc.DriverDataSource.getConnection(DriverDataSource.scala:101)
    at slick.jdbc.DataSourceJdbcDataSource.createConnection(JdbcDataSource.scala:68)
    at slick.jdbc.JdbcBackend$BaseSession.<init>(JdbcBackend.scala:453)
    at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:46)
    at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:37)
    at slick.basic.BasicBackend$DatabaseDef.acquireSession(BasicBackend.scala:249)
    at slick.basic.BasicBackend$DatabaseDef.acquireSession$(BasicBackend.scala:248)
    at slick.jdbc.JdbcBackend$DatabaseDef.acquireSession(JdbcBackend.scala:37)
    at slick.basic.BasicBackend$DatabaseDef$$anon$2.run(BasicBackend.scala:274)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Jun 25, 2019 2:10:40 PM org.postgresql.core.v3.ConnectionFactoryImpl log
WARNING: IOException occurred while connecting to 68.183.40.242:5432
java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:69)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:156)
    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:452)
    at org.postgresql.Driver.connect(Driver.java:254)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:341)
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:193)
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:430)
    at com.zaxxer.hikari.pool.HikariPool.access$500(HikariPool.java:64)
    at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:570)
    at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:563)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

我正在使用docker-compose,ubuntu 18.04和postgreSQL 10。

你知道我可能在哪里出错吗?

1 个答案:

答案 0 :(得分:0)

尝试在您的docker-compose.yml中使用它:

network: host

并更改IPs中的docker-compose.yml以使用您在UBUNTU上使用的内容,或者现在只需使用localhost