Im really newbie to docker, so I was following this tutorial of how to dockerize it. The image builds fine but when running the container, prisma cannot connect to the database. The database is hosted in supabase
.
In the docker-compose.yaml
Im setting the connection string as
environment:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@$db.ieikcwdztopjvzzgdppu.supabase.co:5432/${POSTGRES_DB}
This is the error Im getting
PrismaClientInitializationError: Authentication failed against database server at `db.ieikcwdztopjvzzgdppu.supabase.co`, the provided database credentials for `postgres` are not valid.
I even tried to hardcode the connection string without any env reference, but i got the same result.
This is the full docker-compose.yaml
services:
api:
build:
dockerfile: Dockerfile
context: .
# Only will build development stage from our dockerfile
target: development
depends_on:
- postgres
env_file:
- .env
environment:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@$db.ieikcwdztopjvzzgdppu.supabase.co:5432/${POSTGRES_DB}
postgres:
image: postgres
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_PORT: ${POSTGRES_PORT}
ports:
- '5432:5432'
volumes:
- docker-nest-postgres:/var/lib/postgresql/data
volumes:
- .:/usr/src/app
# Run a command against the development stage of the image
command: npm run start:dev
ports:
- 3000:3000
So my problem was that the password had the character $
. So it was getting replaced when generating the image. So i escaped it as $$