我正试着和普里斯玛一起工作。我已经在GitHub问题和StackOverflow上尝试了可用的解决方案。
我使用以下命令安装了Prisma
npm install -g prisma我已经在系统中安装了docker和docker-compose。
下面是我的docker合成文件
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.34
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: host.docker.internal
database: db
schema: public
user: prisma
password: prisma
ssl: false
rawAccess: true
port: '5432'
migrations: true
postgres:
image: postgres:11
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres: ~因此,现在我尝试使用以下命令启动我的容器
docker-compose up -d现在,我使用以下命令检查容器是否运行正常。
docker-compose ps
以下是输出
Name Command State Ports
------------------------------------------------------------------------------------------
graphql-prisma_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp
graphql-prisma_prisma_1 /bin/sh -c /app/start.sh Up 0.0.0.0:4466->4466/tcp现在,如果我尝试执行以下命令
prisma deploy
docker-compose ps以下是输出
environment FetchError: request to http://localhost:4466/management failed, reason: connect ECONNREFUSED 127.0.0.1:4466
environment at ClientRequest.<anonymous> (/home/tomonso/.nvm/versions/node/v12.4.0/lib/node_modules/prisma/node_modules/node-fetch/lib/index.js:1393:11)
environment at ClientRequest.emit (events.js:200:13)
environment at ClientRequest.EventEmitter.emit (domain.js:471:20)
environment at Socket.socketErrorListener (_http_client.js:402:9)
environment at Socket.emit (events.js:200:13)
environment at Socket.EventEmitter.emit (domain.js:471:20)
environment at emitErrorNT (internal/streams/destroy.js:91:8)
environment at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
environment at processTicksAndRejections (internal/process/task_queues.js:84:9) +0ms
environment FetchError: request to http://localhost:4466/management failed, reason: connect ECONNREFUSED 127.0.0.1:4466
environment at ClientRequest.<anonymous> (/home/tomonso/.nvm/versions/node/v12.4.0/lib/node_modules/prisma/node_modules/node-fetch/lib/index.js:1393:11)
environment at ClientRequest.emit (events.js:200:13)
environment at ClientRequest.EventEmitter.emit (domain.js:471:20)
environment at Socket.socketErrorListener (_http_client.js:402:9)
environment at Socket.emit (events.js:200:13)
environment at Socket.EventEmitter.emit (domain.js:471:20)
environment at emitErrorNT (internal/streams/destroy.js:91:8)
environment at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
environment at processTicksAndRejections (internal/process/task_queues.js:84:9) +3ms
command Failed to fetch server version +0ms
command TypeError: Cannot read property 'replace' of null +0ms
environment FetchError: request to http://localhost:4466/management failed, reason: connect ECONNREFUSED 127.0.0.1:4466
environment at ClientRequest.<anonymous> (/home/tomonso/.nvm/versions/node/v12.4.0/lib/node_modules/prisma/node_modules/node-fetch/lib/index.js:1393:11)
environment at ClientRequest.emit (events.js:200:13)
environment at ClientRequest.EventEmitter.emit (domain.js:471:20)
environment at Socket.socketErrorListener (_http_client.js:402:9)
environment at Socket.emit (events.js:200:13)
environment at Socket.EventEmitter.emit (domain.js:471:20)
environment at emitErrorNT (internal/streams/destroy.js:91:8)
environment at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
environment at processTicksAndRejections (internal/process/task_queues.js:84:9) +4ms
environment FetchError: request to http://localhost:4466/management failed, reason: connect ECONNREFUSED 127.0.0.1:4466
environment at ClientRequest.<anonymous> (/home/tomonso/.nvm/versions/node/v12.4.0/lib/node_modules/prisma/node_modules/node-fetch/lib/index.js:1393:11)
environment at ClientRequest.emit (events.js:200:13)
environment at ClientRequest.EventEmitter.emit (domain.js:471:20)
environment at Socket.socketErrorListener (_http_client.js:402:9)
environment at Socket.emit (events.js:200:13)
environment at Socket.EventEmitter.emit (domain.js:471:20)
environment at emitErrorNT (internal/streams/destroy.js:91:8)
environment at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
environment at processTicksAndRejections (internal/process/task_queues.js:84:9) +1ms
Error: Could not connect to server at http://localhost:4466. Please check if your server is running.
at Deploy.<anonymous> (/home/tomonso/.nvm/versions/node/v12.4.0/lib/node_modules/prisma/node_mod
ules/prisma-cli-core/src/commands/deploy/deploy.ts:137:13)
at step (/home/tomonso/.nvm/versions/node/v12.4.0/lib/node_modules/prisma/node_modules/prisma-cli-core/dist/commands/deploy/deploy.js:45:23)
at Object.next (/home/tomonso/.nvm/versions/node/v12.4.0/lib/node_modules/prisma/node_modules/prisma-cli-core/dist/commands/deploy/deploy.js:26:53)
at fulfilled (/home/tomonso/.nvm/versions/node/v12.4.0/lib/node_modules/prisma/node_mod
ules/prisma-cli-core/dist/commands/deploy/deploy.js:17:58)
at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:25136) [DEP0066] DeprecationWarning:
OutgoingMessage.prototype._headers is deprecated
util timed out +0ms
output Exiting with code: 0 +0ms发布于 2019-07-26 17:35:32
首先,如果你使用docker logs检查prisma日志,你会发现很多错误。这里有几个问题:
host.docker.internal只能在docker for mac/docker for windows上运行。如果以上是你的真实情况,那么你想使用host machine's 5432 port访问postgres's 5342 port。如果出现这种情况,则需要在postgres service中指定端口映射- "5432:5432"。
如果你只在linux上工作,那么host.docker.internal甚至不能被识别。
实际上,无论您使用windows/mac/linux,您只需要将host: host.docker.internal替换为host: postgres,prisma container就可以直接访问postgres container,不需要主机干预,您可以参考this,在页面中搜索User-defined bridges provide automatic DNS resolution between containers获取更多帮助。
prisma service要建立D18数据库时,D19甚至还没有启动,您需要定义启动顺序,以确保D20在D21之前准备就绪,您可以参考C22:但是,如果您查看它的入口点,您可以看到以下内容:
bash-4.4# cat start.sh #!/bin/bash set -e /app/prerun_hook.sh /app/bin/prisma-local
在这里,/app/prerun_hook.sh是一个钩子,供使用此映像执行某些预操作的用户使用,因此您只需在此文件中添加一些服务启动保证代码,即可确保数据库服务已经启动。
最后,接下来是一个可行的解决方案:
docker-compose.yaml:
version: '3'
services:
prisma:
build: .
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: postgres
host: postgres
database: db
schema: public
user: prisma
password: prisma
ssl: false
rawAccess: true
port: '5432'
migrations: true
depends_on:
- "postgres"
postgres:
image: postgres:11
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres: ~文档文件:
FROM prismagraphql/prisma:1.34
COPY ./prerun_hook.sh /app/prerun_hook.sh
RUN chmod +x /app/prerun_hook.sh && \
apk add postgresql-clientprerun_hook.sh:
#!/bin/sh
set -e
until PGPASSWORD="prisma" psql -h postgres -U "prisma" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"然后,如果检查docker日志,您将看到下一步,这意味着它现在是ok的:
Postgres is up - executing command
No log level set, defaulting to INFO.
[INFO] {} - Starting...
[INFO] {} - Start completed.
[INFO] Initializing workers...
[INFO] Obtaining exclusive agent lock...
[INFO] Obtaining exclusive agent lock... Successful.
[INFO] Successfully started 1 workers.
[INFO] Deployment worker initialization complete.
Server running on :4466https://stackoverflow.com/questions/57215546
复制相似问题