D
Dokploy•4mo ago
Ganapathy

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
Ganapathy
GanapathyOP•4mo ago
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.
Siumauricio
Siumauricio•4mo ago
Currently you cannot access the database in build time, the only way is to expose the database
Siumauricio
Siumauricio•4mo ago
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, ...
Siumauricio
Siumauricio•4mo ago
is more a docker issue than dokploy I guess
Ganapathy
GanapathyOP•4mo ago
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.
{
"Test": [
"CMD",
"curl",
"-f",
"http://localhost:8000/api/health"
],
"Interval": 30000000000,
"Timeout": 10000000000,
"StartPeriod": 30000000000,
"Retries": 3
}
{
"Test": [
"CMD",
"curl",
"-f",
"http://localhost:8000/api/health"
],
"Interval": 30000000000,
"Timeout": 10000000000,
"StartPeriod": 30000000000,
"Retries": 3
}
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.
No description
No description
Ganapathy
GanapathyOP•4mo ago
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!

Did you find this page helpful?