Creating with existed data occurred error

prisma

#1

postgres (PostgreSQL) 10.4
prisma/1.8.3 (darwin-x64) node-v8.11.2
Docker version 18.03.1-ce, build 9ee9f40

The error shows when using the local postgresql database.

FetchError: request to http://localhost:4466/management failed, reason: socket hang up
at ClientRequest. (/usr/local/lib/node_modules/prisma/node_modules/node-fetch/lib/index.js:1376:11)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketOnEnd (_http_client.js:423:9)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Exiting with code: 1


#2

Can you share your docker-compose.yml file?


#3
version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.8
    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: 127.0.0.1
            port: '5432'
            database: water_test
            schema: public
            user: username
            password: nibuzhidao
            migrations: false

#4

What information does docker logs -f <prisma container id> reveal?
You can find out <prisma container id> by running docker ps.


#5

docker ps

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
5bd799fc4516        prismagraphql/prisma:1.8   "/bin/sh -c /app/sta…"   2 weeks ago         Up 9 seconds        0.0.0.0:4466->4466/tcp   test6_prisma_1
50684e3f739f        prismagraphql/prisma:1.8   "/bin/sh -c /app/sta…"   2 weeks ago         Up 12 days          0.0.0.0:4465->4465/tcp   test5_prisma_1
bd0cf45fbf21        postgres                   "docker-entrypoint.s…"   2 weeks ago         Up 12 days          5432/tcp                 test5_postgres_1

docker logs 5bd799fc4516

exception in thread "main" java.sql.SQLTransientConnectionException: database - Connection is not available, request timed out after 5001ms.
	at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:548)
	at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186)
	at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:83)
	at slick.jdbc.hikaricp.HikariCPJdbcDataSource.createConnection(HikariCPJdbcDataSource.scala:18)
	at slick.jdbc.JdbcBackend$BaseSession.<init>(JdbcBackend.scala:439)
	at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:47)
	at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:38)
	at slick.basic.BasicBackend$DatabaseDef.acquireSession(BasicBackend.scala:218)
	at slick.basic.BasicBackend$DatabaseDef.acquireSession$(BasicBackend.scala:217)
	at slick.jdbc.JdbcBackend$DatabaseDef.acquireSession(JdbcBackend.scala:38)
	at slick.basic.BasicBackend$DatabaseDef$$anon$2.run(BasicBackend.scala:239)
	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)
Caused by: org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Seems prisma is not able to connect the database.

My local database is able to connect.

Ted:tedzhang$ psql -d water_test -p 5432 -U tedzhang -W
Password for user tedzhang:
psql (10.4)
Type "help" for help.

water_test=#

#6

Change the host to:
host: host.docker.internal
in your docker-compose.


#7

More information on this here: https://stackoverflow.com/a/43541681/1176596