1

I’m deploying a Node.js + Prisma backend using Docker on my VPS.
PostgreSQL is NOT in Docker — it runs directly on the VPS host (Ubuntu).
My backend is running inside Docker using docker compose.

DB_USER=vloq

DB_PASSWORD=******

DB_HOST=host.docker.internal

DB_PORT=5432

DB_NAME=furnix-staging

DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}"

Since the DB runs on the host machine, I correctly use

What works

From inside the running Docker container, I can install PostgreSQL client and successfully connect:

docker exec -it furnix-backend sh

apk add postgresql-client

psql -h host.docker.internal -U vloq -d furnix-staging

What fails

Prisma inside the backend container throws:

PrismaClientInitializationError:

Can't reach database server at `123:5432`

Important:
123 is NOT in my .env.
It looks like Prisma is reading an old or wrong DATABASE_URL.

Docker logs show:

Can't reach database server at `123:5432`

Even though .env says:

host.docker.internal

What I suspect

  • Docker image may be caching the old .env

  • DATABASE_URL may not be passed correctly by docker-compose

  • Prisma may not see environment variables correctly during runtime

  • docker compose up -d --build does not reload .env

docker-compose.yml

services:
  furnix-backend:
    build: .
    container_name: furnix-backend
    restart: always
    ports:
      - "7778:7777"
    env_file:
      - .env
    environment:
      NODE_ENV: production
    command: ["node", "dist/server.js"]

✔️ What I already tried

  • Rebuilt without cache:

    docker compose down

    docker compose build --no-cache

    docker compose up -d

    Verified .env on host — it is correct.

    Verified DB connectivity from inside container.

    Verified Prisma works locally.

My Question

Why is Prisma inside the Docker container still trying to connect to:

123:5432

even though:

DB_HOST=host.docker.internal

is set correctly in .env, and psql from inside the container can connect successfully?

How can I ensure Docker / Prisma loads the correct .env so DATABASE_URL resolves properly?

New contributor
Kaif Ansari is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • (1) list old container docker container ls -a (2) find old container id like xxxx . (3) delete old container and volume: docker container rm -f -v xxxx Commented Nov 26 at 10:34
  • Is there also a .env or similar file built into your image? Can you log process.env.DATABASE_URL at startup to see if the right thing is coming out? Commented Nov 26 at 12:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.