'Unable to load .flaskenv into Docker

I'm trying to containerize my flask application using Docker. The env variables which include client secrets, db creds, etc. are stored in .flaskenv. The application runs fine when run from terminal. But, when I build the application using Docker and do docker run, the env variables are not loaded and the API requests fail. I have tried using other methods to achieve the same, for example, using a config.py file which contains the class Config. I import that class into flask entrypoint file and load into flask app using app.config.from_object(config.Config) which seems to work fine on local but, fails when run using docker with KeyError: "CLIENT_ID", which is an env variable in the application.

Note: My application does not use docker-compose and I am looking for a solution without using the same.

Please mention if any further details are required. Thanks in advance!

Dockerfile -

FROM <python3.9 image source>

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV FLASK_APP development

RUN apt-get update \
  && rm -rf /var/lib/apt/lists/*

COPY pip /pip

ARG PIP_CONFIG_FILE=/pip/pip.conf
RUN python3.9 -m ensurepip
RUN python3.9 -m pip install --no-cache-dir <project-package>==0.1.0 \
    && useradd -U app_user --home /app \
    && rm -rf /pip

WORKDIR /app
USER app_user:app_user
COPY --chown=app_user:app_user docker/entrypoint.sh .
COPY --chown=app_user:app_user docker/start.sh .
RUN chmod +x *.sh

# ENV PYTHONPATH "${PYTHONPATH}:/app"

ENTRYPOINT [ "./entrypoint.sh" ]
CMD [ "./start.sh" ]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source