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

Error: Prisma no puede conectarse a la base de datos PostgreSQL en Docker #1288

Open
1 task done
Franruaben11 opened this issue Mar 6, 2025 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@Franruaben11
Copy link

Welcome!

  • Yes, I have searched for similar issues on GitHub and found none.

What did you do?

Issue with Prisma in Docker (v2.2.0)

Description

After updating to version 2.2.0, Prisma cannot connect to PostgreSQL in Docker, throwing the following error:

Error: P1001: Can't reach database server at localhost:5432

In version 1.8.2, it works without any issues.

Details

  • I am using Google Cloud.
  • PostgreSQL in Docker has IP: 172.23.0.3, but Prisma keeps trying to connect to localhost:5432.
  • I tried using DATABASE_URL=postgresql://user:password@postgres:5432/evolution and DATABASE_URL=postgresql://user:[email protected]:5432/evolution, but neither worked.
  • docker exec -it evolution_api printenv fails with broken pipe.

Question

Does anyone have any idea how to make it work with a newer version than 1.8.2?

Thanks for the help.

What did you expect?

use v2.2.0

What did you observe instead of what you expected?

Prisma fails to connect to the PostgreSQL database and throws the following error: Error: P1001: Can't reach database server at localhost:5432

Screenshots/Videos

NO

Which version of the API are you using?

2.2.0 (Works fine on 1.8.2)

What is your environment?

Linux

Other environment specifications

  • Cloud Provider: Google Cloud
  • PostgreSQL in Docker IP: 172.23.0.3, but Prisma keeps trying to connect to localhost:5432.
  • Tried DATABASE_URL values:
    • postgresql://user:password@postgres:5432/evolution
    • postgresql://user:[email protected]:5432/evolution
  • Issue with Docker command:
    • docker exec -it evolution_api printenv fails with broken pipe.

If applicable, paste the log output

Error: P1001: Can't reach database server at localhost:5432

Additional Notes

No response

@Franruaben11 Franruaben11 added the bug Something isn't working label Mar 6, 2025
@Franruaben11
Copy link
Author

Response:

The issue was in the prisma/postgresql-schema.prisma file, specifically with the datasource configuration:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_CONNECTION_URI")  // Use DATABASE_CONNECTION_URI!
}

In my .env file, I was using the DATABASE_URL variable instead of DATABASE_CONNECTION_URI. The value of the environment variable in the .env file was configured like this:

Before:

DATABASE_URL=postgresql://myUser:myPass@postgres:5432/ev.....

After:

DATABASE_CONNECTION_URI=postgresql://myUser:myPass@postgres:5432/ev....

After making this change, the connection to the database worked correctly, and the issue was resolved.
You can now copy and paste this into a GitHub issue as a response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant