Good evening! I am having an issue with prisma run...
# orm-help
e
Good evening! I am having an issue with prisma running in a docker container. To have my Node.js server read from my Postgres server using prisma I have to set the db-url to be the container name of the db service. But to seed or migrate the server prisma needs the db-url to be set to the IP (0.0.0.0). Have anyone here had a similar issue and / or can point me in the right direction?
b
Not too sure if I understand your question. But my understanding is that you only need one connection string that links Prisma to the database. Secondly, in your
compose.yml
ensure that the container port for your db is exposed to your host machine via port mapping. Another thing to remember is that if you have another instance of db server running on the same port from your host, you need to stop it. Once all these are in place, running
docker-compose up
should get you up and running. Here is a simple working example, you just need to prepare your
.env
like below:
Copy code
DATABASE_URL=<postgres://postgres:postgres@localhost:5432/hackernews-db>
Check the code here: https://github.com/chaiwa-berian/hackernews-node
e
Thank you Berian! DevOps is a completely new field for me and trying to get the hang of it before a coding interview I have upcoming which will have me create a working docker backend with an attached postgres server. Thank you for taking the time!
The issue I am having is that I can either db migrate using
0.0.0.0:{PORT}
but then I get an error that I can’t connect to the db when I seed the db through the seed command If I have the link be the container-name for the postgres I can seed the db, but I can no longer migrate. The fault lies more likely than not with me somewhere and that I don’t really grasp how the migration works.
I am currently reading up on the Network functionality of Docker, it seems like the solution might lie in there. Will report back!
b
I am also learning this type of stuff. I am curious to know how you solve this in the end. Out of curiosity, are you using
docker-compose
?
e
Yes, running the node server and a postgres database through docker-compose up. Am hoping to be able to squeeze in a vue app in there as well, but need to cross this bridge first 😅