Trying to connect to the DB during Next JS build
I'm trying to deploy a Next JS app that connects to the MySQL DB during build time. I tried both Nixpacks & Dockerfile build types without success. The DB is running in another container on the same server. It isn't exposed to the internet.
Things I've tried so far:
1. Using the 'External Port' feature to expose the container port to the host and provide localhost (also tried 127.0.0.1) as host and the appropriate port.
2. Using the internal connection URL from Dokploy.
Both times, I saw the Prisma error "Please make sure your database server is running at...."
Any help will be appreciated. Thanks!
6 Replies
I fixed the issue by building and starting the app using the custom command. Dockerfile just installs the dependencies & copies the source code to the image. Not sure if this is the correct way of doing things, but it works.
Currently you cannot access the database in build time, the only way is to expose the database
you can see here https://github.com/Dokploy/dokploy/issues/507
GitHub
Connecting Next.js with server actions to database with Internal Co...
To Reproduce After I created the Next application and deployed it to Dokploy and connected to the Dokploy database (PostgreSQL), communication works if I connect via an external connection string, ...
is more a docker issue than dokploy I guess
Thank you for the reply. Great project! I agree with you on this. I did my research, it is a docker limitation.
I'm running into another issue trying to set up zero-downtime deployment. As I said earlier, as a workaround to the docker limitation, I use custom command to build and start the application. The command -
npm run build && pm2-runtime start npm --name 'bgmanual.com' -- start
. I added the following piece of code in the health check textbox in the swarm settings. The next JS app runs on port 8000 in the container.
Now, whenever I deploy, Dokploy keeps on starting new containers and the old one still runs. It never seems to stop. What am I missing? I've added screenshots for your reference. Sorry about the trouble. Thank you for the help.

The container didn't have
curl
installed. Once I installed it, the issue was fixed and zero downtime deployment works 🔥 Once again, great project! Soon I'll use it in production. Thank you!