Skip to main content

Build Env Vars

You can add environment variables to your build process.

Inside your app environment you have a Env Vars tab, there when you add a new env var you can select the Used for field, that can be Deploy, Build or Both. So for build env vars you should choose Build or Both.

Check Deploy Env Vars for more info about deploy env vars.

It's important to declare them as arguments in your Dockerfile, we already declare all of them in our preset Dockerfiles but if you are using a custom Dockerfile you need to declare them.

This is a security restriction of Docker. If you don't declare them they will not be available in your build process.

For example, if you Next.js build needs to have access to your MONGODB_URL you need to declare it in your Dockerfile:

FROM node:18-alpine AS base

# ...

FROM base AS builder
ARG MONGODB_URL

ENV DB_URL=$MONGODB_URL

RUN yarn build

# ...

It's required to declare your ARGs in your Dockerfile before using them and after the closest FROM where it is used.