Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Can't connect to database during Dockerfile buildtime #4404

Open
vendramini opened this issue Nov 26, 2024 · 3 comments
Open

[Bug]: Can't connect to database during Dockerfile buildtime #4404

vendramini opened this issue Nov 26, 2024 · 3 comments
Labels
🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization.

Comments

@vendramini
Copy link

Error Message and Logs

Hello there!

I'm using new Prisma TypedSQL feature, which relies on an active database connection to generate its types: https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/typedsql

When running it, it says that the database isn't running - however it is, my app is live, I'm able to connect through MySQL Workbench, etc.

2024-Nov-26 15:05:27.207981
 > [nextjs  8/10] RUN npx prisma generate --sql:
2024-Nov-26 15:05:27.207981
6.964 Error: Errors while reading sql files:
2024-Nov-26 15:05:27.207981
6.964 
2024-Nov-26 15:05:27.207981
6.964 In prisma/sql/getBestSellingProductsByPeriod.sql:
2024-Nov-26 15:05:27.207981
6.964 Error: P1001
2024-Nov-26 15:05:27.207981
6.964 
2024-Nov-26 15:05:27.207981
6.964 Can't reach database server at `x.y.z.w:5432`
2024-Nov-26 15:05:27.207981
6.964 
2024-Nov-26 15:05:27.207981
6.964 Please make sure your database server is running at `x.y.z.w:5432`.

I've tried using both internal URL from Coolify and the public database URL, neither of them work. The database is also hosted on the same coolify instance.

Steps to Reproduce

  1. Enable https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/typedsql on Prisma schema.
  2. run npx prisma generate --sql during Dockerfile build time.
  3. It needs connection to database, which fails.

Example Repository URL

No response

Coolify Version

v4.0.0-beta.372

Are you using Coolify Cloud?

No (self-hosted)

Operating System and Version (self-hosted)

Alpine 3.20.3

Additional Information

No response

@vendramini vendramini added 🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization. labels Nov 26, 2024
@djsisson
Copy link
Contributor

@vendramini this is by design, docker build containers are not connected to any network, they run on the host

if you have mapped to host then serverip:5432 should still work, or you can use your db hostname if you add entry in /etc/hosts either manually or using a script

@vendramini
Copy link
Author

When you say "mapped to host" you mean this?
Image

It's allowed to connect to predefined networks and it doesn't work if I try to connect with internal URL.

@djsisson
Copy link
Contributor

@vendramini no that just means its in the coolify network , but your host doesnt know about those hostnames hence the error

you would need to add port mappings to teh host or add the ip/hostname to your /etc/hosts file on the host

or run it in post deployment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization.
Projects
None yet
Development

No branches or pull requests

2 participants