NextJS + Prisma + Docker | "can't reach db server"
I will supply all of my files in comments because of the character limit.
The first issue is that when I run my docker compose up, it generates the prisma client, then it runs npm build. On the build, it cannot connect to the database server (shown on the included image)
For context, I am using this as a reference: https://github.com/99lalo/nextjs-prisma-docker
docker-compose.yml
16 Replies
Dockerfile
: https://pastebin.com/QHJdMmJi
package.json
: https://pastebin.com/7wfWMjQf
.env
: https://pastebin.com/PYKkx8k2
I can supply anything else that might be needed. I've been stuck on this for a couple of days just trying different things 😦So your postgres instance is essentially on the same image?
Note; I don't actually know how to fix this, but it's a docker networking issue
I can almost guarantee your host isn't correct
DATABASE_URL="postgresql://postgres:postgres@postgres:5432/postgres?schema=public"
The really real question here is: is this how you actually plan to deploy it out live?I had planned to use this docker compose, yes. However, I'm willing to change it up if need be. I'm just trying to get anything working then I will work towards a cleaner solution.
I'm all ears 🙂
What I do, is have a postgres server on my local rig, and just point my local build at it. For any remote deployment I'll have RDS/GCP SQL/DO db/etc
I see. So you just decouple the frontend and db?
Look, you can save some bucks having the db on the same rig (make sure it has a persistant volume or it's gonna go poof on reboot), but the hassle isn't worth it imo as I can't think of an implementation I've seen in the last 12 years that actually used an on-server postgres like this except for a test suite
That's not saying it's not done, or that you shouldn't solve this, but the is solving it gonna be worth it lol
I'm also just needing something quick. This is something needed for work that will be deployed for a few weeks and then taken down. I just want to take the path of least resistance lol
tl;dr, figure out how cross service chatter actually works so you can address the postgres image from your front/backend image
Digital ocean db's are $15/month, RDS has a free tier, Neon... I'm not impressed with their pricing unless they've fixed egress pricing in the past year
So, is your time worth more than $15 is what I'm saying
I hear you, and I'm willing to change how I'm hosting. I just have to figure out how to navigate this with work things. I don't directly have access to any of our hosting stuff.
Thanks for the input and I will go back to the drawing board
and yes, this is super insanely common
I was following step 1. I've done very similar things in the past with Docker and using the container name has always worked. Just not sure why it isn't in this one case haha
I'm just going to throw it in it's own container and use host ip
So, I gave it (bing copilot) your dockerfile and it pooped out this
SO, I'm interested, can you connect to that postgres image with psql or dbeaver or something using that connection string?
I was previously using adminer and could connect with the docker container name. But I'm not sure about the connection string
I just learned about this db host.
https://www.instantdb.com/
InstantDB: A Modern Firebase
We make you productive by giving your frontend a real-time databse.
it's technically postgres on the backside, and stupid new, so it may not work with prisma but who knows
thanks for sharing.
I'll keep you updated what I end up doing