postgresql 如何将NestJS与Prisma服务器对接?

0lvr5msh  于 2024-01-07  发布在  PostgreSQL
关注(0)|答案(1)|浏览(127)

我是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

pobjuy32

pobjuy321#

所以我的问题是,密码有字符$。所以它被替换时生成的图像。所以我转义为$$

相关问题