我正在按照本教程逐步尝试使用Nexus运行Graphql pyramida。 https://www.prisma.io/docs/get-started/03-build-graphql-servers-with-prisma-TYPESCRIPT-t201/
当我在计算机上运行时
nodemon dev
运行正常
访问http://localhost:4466/_admin
很好。
在http://localhost:4000/
中进行简单查询(根据官方文档)可以正常工作。
mutation {
createUser(data: { name: "Jane" }) {
id
}
}
//return
// all working
{
"data": {
"createUser": {
"id": "5cd22c1b73c7b2000782c07b"
}
}
}
现在我需要在docker容器中运行index.ts
,所以我创建了容器
Dockerfile
FROM node:10 as installer
WORKDIR /src
COPY package.json package-lock.json ./
RUN npm install
FROM node:10-alpine
RUN mkdir /src
WORKDIR /src
COPY --from=installer /src .
COPY . .
RUN npm install -g nodemon
RUN npm install -g typescript
EXPOSE 4000
CMD ["nodemon", "dev"]
docker-compose.yml文件
version: '3'
services:
app:
build: .
container_name: "demoprisma_app"
volumes:
- "./:/src/"
ports:
- "4500:4000"
prisma:
image: prismagraphql/prisma:1.32
restart: always
ports:
- '4466:4466'
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: mongo
uri: mongodb://prisma:prisma@mongo
mongo:
image: mongo:3.6
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: prisma
MONGO_INITDB_ROOT_PASSWORD: prisma
ports:
- '27017:27017'
volumes:
- mongo:/var/lib/mongo
volumes:
mongo: ~
当我在浏览器app
中访问容器http:localhost:4500
并进行相同的查询时
mutation {
createUser(data: { name: "Jane" }) {
id
}
}
发生此错误
{
"data": null,
"errors": [
{
"message": "request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createUser"
]
}
]
}
我认为此错误是因为Docker容器网络,但是我不确定如何在容器内部制作index.ts
您可以使用我的github中的错误克隆示例项目
https://github.com/rollrodrig/prismademotest
只需run
docker-compose up
即可看到错误