我是docker的新手,所以我遵循了这个如何将其dockerize的教程。镜像构建得很好,但在运行容器时,prisma无法连接到数据库。数据库托管在supabase
中。
在docker-compose.yaml
Im中,将连接字符串设置为
environment:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@$db.ieikcwdztopjvzzgdppu.supabase.co:5432/${POSTGRES_DB}
字符串
这是我得到的错误
PrismaClientInitializationError: Authentication failed against database server at `db.ieikcwdztopjvzzgdppu.supabase.co`, the provided database credentials for `postgres` are not valid.
型
我甚至尝试在没有任何env引用的情况下硬编码连接字符串,但我得到了相同的结果。
这是完整的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
型
1条答案
按热度按时间pobjuy321#
所以我的问题是,密码有字符
$
。所以它被替换时生成的图像。所以我转义为$$