I'm encountering a persistent P1000 Authentication Failed error when trying to connect Prisma to a PostgreSQL database running in Docker. Despite having correct credentials and a running container, Prisma migrations fail with authentication errors.
File Structure
ecomm/
├── prisma/
│ └── schema.prisma
├── src/
│ ├── generated/ # (if using custom Prisma output)
│ ├── bin.ts
│ ├── index.ts
│ └── db.ts
├── dist/ # (generated after build)
│ ├── bin.js
│ ├── index.js
│ └── db.js
├── node_modules/
├── .env
├── .gitignore
├── package.json
├── package-lock.json
├── tsconfig.json
└── README.md
package.json:
{
"name": "ecomm",
"version": "1.0.0",
"scripts": {
"build": "prisma generate && tsc",
"start": "node dist/bin.js",
"dev": "ts-node src/bin.ts"
},
"type": "commonjs",
"dependencies": {
"@prisma/client": "^6.16.1",
"express": "^5.1.0"
},
"devDependencies": {
"@types/express": "^5.0.3",
"@types/node": "^20.0.0",
"prisma": "^6.16.1",
"typescript": "^5.0.0",
"ts-node": "^10.9.0"
}
}
prisma schema
generator client {
provider = "prisma-client-js"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Request{
id Int @id @default(autoincrement())
a Int
b Int
answer Int
type Type
}
enum Type{
ADD
MUL
}
.env:
DATABASE_URL="postgresql://postgres:mysecretpassword@localhost:5432/postgres"
Error Details Command that fails:
npx prisma migrate dev --name init
Error output:
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "localhost:5432"
Error: P1000: Authentication failed against database server, the provided database credentials for `postgres` are not valid.
Please make sure to provide valid database credentials for the database server at the configured address.
Docker commands I've used:
# Start PostgreSQL container
docker run -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres
# Verify container is running
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1e171459a61 postgres "docker-entrypoint.s…" 26 minutes ago Up 26 minutes 0.0.0.0:5432->5432/tcp sweet_chaplygin
What I've Tried
Verified container is running - docker ps shows the container is up
Double-checked credentials - Password matches in both Docker command and DATABASE_URL
Tested different connection strings - Tried various formats with same result
Restarted containers multiple times - Same error persists
Checked for port conflicts - Port 5432 appears to be free