Can we access environment variables inside the Dockefile?

Issues information

  • OS:
  • databases: postrges
  • Programming language and version:
  • Link to your project on Github/Gitlab:

Your issue

Texto de origem
I’m trying to get Qovery Environment variables to create .env and ormconfig.js. See commented lines on Dockerfile below.

I will be glad if someone share…

Dockerfile content (if any)

FROM node:12-alpine

WORKDIR /app

COPY . .

RUN yarn

RUN yarn build

#RUN cp .env.production dist/.env
#RUN mv .env.production .env
#RUN cp ormconfig.production.js dist/ormconfig.js
#RUN mv ormconfig.production.js ormconfig.js

RUN yarn typeorm migration:run

RUN rm -Rf src

EXPOSE 3000

CMD ["node", "dist/main/server.js"]

Hello,
Here, you already copied all your file in the image (COPY . .). If you want do some specific move I would rather use COPY than any RUN + cmd.

I think this should work instead of the 4 commented line :
COPY .env.production ./dist/.env
COPY ormconfig.production.js ./dist/ormconfig.js

Hi @Enzo !

I agree with you said, thank you! I’ll fix it.

But this is not my question… :frowning:

My bad, I didn’t get the question then. You’re asking if you can get env vars from Qovery directly in your Dockerfile ? If that’s it, no you can’t.

The best way to do it is to have a config file to use variables locally. I can see you’re working with node. I usually used config for this purpose in my projects. The second part of the deal is to set exactly the same variables in Qovery environnment with application scope