prisma env variable `DATABASE_URL` not found when ...
# orm-help
y
prisma env variable
DATABASE_URL
not found when used docker. in my
docker-compose.yml
, i'm passing
env_file
directive.
Copy code
version: "3.3"
services:
  myapp:
    build:
      context: .
      dockerfile: ./Dockerfile
    env_file:
      - .env.dev
this doesn't seem to work. in docker container, it ran
npx prisma migrate deploy
and i'm getting DATBASE_URL is missing
w
Please post your
Dockerfile
y
Copy code
FROM node:16.10-alpine

WORKDIR /usr/src/app

RUN npm install -g npm@8.7.0

COPY ./package.json ./package-lock.json ./

RUN npm install

COPY ./tsconfig.json ./tsconfig.build.json ./nest-cli.json ./.eslintrc.js ./.prettierrc ./start-container.sh ./

COPY ./src/ ./src

COPY ./prisma/ ./prisma

COPY ./test/ ./test

RUN npx prisma migrate deploy

RUN npm run start
w
You might need to add
prisma generate
y
tried. same error.
i added above deploy line, if that helps.
w
Inside container, what does
set
say?
y
container didn't run because that threw an error, i can skip prisma migrate line and run and check it out.
1
Copy code
DATABASE_URL='<postgresql://awsapi:letmeinmed123@localhost:5436/awsapi_development?schema=public>'
HISTFILE='/root/.ash_history'
HOME='/root'
HOSTNAME='bc7fad1016a7'
IFS=' 
'
LINENO=''
NODE_ENV='development'
NODE_VERSION='16.10.0'
OPTIND='1'
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
POSTGRES_USER='postgres'
PPID='0'
PS1='\w \$ '
PS2='> '
PS4='+ '
PWD='/usr/src/app'
SHLVL='1'
TERM='xterm'
YARN_VERSION='1.22.5'
w
How is your postgreSQL DB running?
Is it in your
docker-compose.yml
?
y
Yes. I suspect maybe some order thing, .env.dev not loaded at the time of npx prisma migrate deploy but it's loaded afterward? I can not be certain
y
Pretty sure it’s related to the fact that the env variable is exposed to the running container, but not the build process
you have to use
ARGS
to pass env variables in your build step
let me see if I can find a link that explains this, I’ve had problems with this in the past
👍 1
w
Another thing to note is that,
```DATABASE_URL='postgresql://awsapi:letmeinmed123@localhost:5436/awsapi_development?schema=public'
...
POSTGRES_USER='postgres'```
Notice the
POSTGRES_USER
value is
postgres
which means you have a mismatch between that and the user set in
DATABASE_URL
:
awsapi:letmeinmed123
. You probably need to set a
POSTGRES_PASSWORD
as well.
y
Ok i think i got it. instead of adding
RUN npx prisma migrate deploy
in Dockerfile you create entrypoint.sh and from there you can do like
Copy code
myapp)
    npx prisma migrate deploy
    npm run start
    ;;
then it recognizes
DATABSE_URL