brs*_*tkr 27 postgresql node.js docker prisma apple-m1
自从我迁移到新的 Apple Silicon 架构后,我使用 nextjs 和 postgres 进行的 docker 设置就不再工作了。我使用prisma的nextjs服务器无法找到docker内的数据库。
prisma 客户端无法通过端口 5432 访问 postgres 数据库。
无法访问数据库服务器
test-postgres:5432
迁移也不起作用并返回上述相同的错误。
docker-compose run --publish 5555:5555 next npx prisma migrate dev
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
postgres:
container_name: 'test-postgres'
restart: unless-stopped
image: 'postgres:13'
ports:
- '15432:5432'
volumes:
- 'pgdata:/var/lib/postgresql/data/'
environment:
POSTGRES_PASSWORD: postgres
Run Code Online (Sandbox Code Playgroud)
.env
DATABASE_URL="postgres://postgres:postgres@localhost:15432/postgres"
Run Code Online (Sandbox Code Playgroud)
我还将arm二进制目标添加到schema.prisma schema.prisma
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-1.1.x", "linux-arm-openssl-1.1.x", "linux-musl"]
previewFeatures = ["orderByRelation", "selectRelationCount"]
}
Run Code Online (Sandbox Code Playgroud)
postgres 容器实际上正在运行,我可以通过 Docker 桌面仪表板看到它。我在 postgres 容器内注意到的一件事是这个错误:
2021-07-21 12:52:58.927 UTC [76] ERROR: relation "_prisma_migrations" does not exist at character 126
Run Code Online (Sandbox Code Playgroud)
有人以前经历过并找到解决方案吗?
[编辑]
克隆存储库,遵循 README.md 并查看 M1 Apple Silicon Machine 上的预期行为:https://github.com/baristikir/prisma-postgres-M1
brs*_*tkr 73
添加?connect_timeout=300到数据库的连接字符串就可以了。
DATABASE_URL="postgres://postgres:postgres@localhost:15432/postgres?connect_timeout=300"
Run Code Online (Sandbox Code Playgroud)
我在 m1 mac mini 上遇到了这个问题,解决方案是将节点版本从 v16.16.0(图像节点:16)更改为 v17.9.1(节点:17),我们在节点:18 上尝试过,它也有效。我将 Dockerfile 更改为
FROM node:16
Run Code Online (Sandbox Code Playgroud)
到
FROM node:17
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25537 次 |
| 最近记录: |