Since I have moved to the new Apple Silicon architecture my docker setup with nextjs and postgres is not working anymore. The database inside the docker cannot be found by the nextjs server where I am using prisma.
The prisma client can’t reach the postgres database on port 5432.
Can’t reach database server at
test-postgres
:5432
The migration also does not work and returns the same error above.
docker-compose run --publish 5555:5555 next npx prisma migrate dev
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
.env
DATABASE_URL="postgres://postgres:postgres@localhost:15432/postgres"
I have also added the arm binary target to the 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"]
}
The postgres container is actually running and I can see it through the Docker Desktop Dashboard. One thing I have noticed inside the postgres container was this ERROR:
2021-07-21 12:52:58.927 UTC [76] ERROR: relation "_prisma_migrations" does not exist at character 126
Have someone experienced it before and found a solution for it?
[EDIT]How to reproduce
clone repo, follow README.md and see expected behaviour on a M1 Apple Silicon Machine: https://github.com/baristikir/prisma-postgres-M1
5
Answers
Adding
?connect_timeout=300
to the connection string of the database did the trick.I had this issue on m1 mac mini, the solution was changing the version of node from v16.16.0(image node:16) to v17.9.1(node:17), we tried on node:18 it works also.
I changed Dockerfile
from
to
I was using 16.17.0 version of Node.
Just switched back to 16.13.2 and the issue is solved.
I got the same issue and I added
?connect_timeout=300
and it worked.I realized it’s taking some time, before connecting to the database especially when it’s from a cloud provider, therefore the error.
With me I just change the database URL:
And it works fine.