I have added environment variables to the "Config Vars" section of my Heroku project. The project is a dockerized create-react-app project. I am able to deploy the app but I have been unable to get the "Config Vars" to map the the environment variables in the docker container.


Here is my dockerfile:

FROM node:10-alpine as builder
ENV 80
ENV REACT_APP_MYAPP_REDIRECT_URI https://myapp.herokuapp.com/#/login

# copy the package.json to install dependencies
COPY package.json yarn.lock ./

# Install the dependencies and make the folder
RUN yarn install && mkdir /react-ui && mv ./node_modules ./react-ui

WORKDIR /react-ui

COPY . .

# Build the project and copy the files
RUN yarn run build

FROM nginx:alpine


COPY ./.nginx/nginx.conf /etc/nginx/conf.d/default.conf

## Remove default nginx index page
RUN rm -rf /usr/share/nginx/html/*

# Copy from the stage 1
COPY --from=builder /react-ui/build /usr/share/nginx/html

CMD sed -i -e 's/$PORT/'"$PORT"'/g' /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'

In the Heroku "Config Vars" I have defined each of the environment variables i.e.

REACT_APP_MYAPP_AUTH_DOMAIN: myapp.us.auth0.com
REACT_APP_MYAPP_REDIRECT_URI: https://myapp.herokuapp.com/#/login

In my React app I am pulling in the environment variables like this:


When I do this locally it will print out the values that I set on my machines environment variables, but when I run this on Heroku it uses the default values that are specified in the dockerfile instead of the environment variables that I specified for the Heroku project.

From the documentation here it says that you are allowed to use the ENV command in the dockerfile for environment variables. Is there something I am missing?

I have looked into the idea of using a heroku.yml file for deploying the project and using the config section for it but as stated in the documentation it says that Variables set in this section do not create runtime config vars. which is what I am trying to do.

Any help would be appreciated.

  • I'm facing the same problem while trying to map the config vars set on the Heroku UI to the ones on my Dockerfile. So far what I have done is tried to used the release phase of Heroku deployment. In this phase you have access to config vars but it limits you to run commands once the container is already running. Anyways, if you managed to find a better solution please let us know.
    – diegocl02
    Feb 9, 2021 at 21:47


You must log in to answer this question.

Browse other questions tagged .