Django failed in build. Not found in env
farhan2401
HOBBYOP

2 years ago

Hi im using dockerfile to deploy my app.
My Dockerfile
> # Use an official Python runtime as a parent image
> FROM python:3.11.9
>
> # Set environment variables
> ENV PYTHONDONTWRITEBYTECODE 1
> ENV PYTHONUNBUFFERED 1
>
> # Set work directory
> WORKDIR /usr/src/app
>
> # install system dependencies
> RUN apt-get update && apt-get upgrade -y && apt-get install -y netcat-openbsd gcc && apt-get clean
>
> # Copy file
> COPY . /usr/src/app/
> RUN pip install -r requirements/production.txt
>
> # Collect static files and migrate
> RUN python manage.py collectstatic --noinput --settings=config.settings.production
> RUN python manage.py migrate --settings=config.settings.production
>
> # Run the application
> CMD ["gunicorn", "--workers=3", "config.wsgi"]

It failed here
> File "/usr/src/app/config/settings/production.py", line 14, in
>
> SECRETKEY = env("DJANGOSECRETKEY") > > ^^^^^^^^^^^^^^^^^^^^^^^^ > > File "/usr/local/lib/python3.11/site-packages/environ/environ.py", line 199, in call > > return self.getvalue(
>
> ^^^^^^^^^^^^^^^
>
> File "/usr/local/lib/python3.11/site-packages/environ/environ.py", line 392, in getvalue > > raise ImproperlyConfigured(errormsg) from exc
>
> django.core.exceptions.ImproperlyConfigured: Set the DJANGOSECRETKEY environment variable

I already put the variables in the project

16 Replies

2 years ago

please attach the dockerfile as a file


farhan2401
HOBBYOP

2 years ago

3995ec84-e5e8-447a-bc3d-a110c9b3e381


farhan2401
HOBBYOP

2 years ago


2 years ago

you have your environment variable named incorrectly


farhan2401
HOBBYOP

2 years ago

Sorry i think on the above i paste the error message wrongly


farhan2401
HOBBYOP

2 years ago

1265338889569046500


farhan2401
HOBBYOP

2 years ago

1265338966299771100


farhan2401
HOBBYOP

2 years ago

1265339023354888200


2 years ago

where is this env function defined?


farhan2401
HOBBYOP

2 years ago

in Dockerfile

1265339271422808000


farhan2401
HOBBYOP

2 years ago

in my django settings


2 years ago

im sorry im not sure how that answered the question?


2 years ago

either way, please see this docs section -


farhan2401
HOBBYOP

2 years ago

okay i try follow this one first


farhan2401
HOBBYOP

2 years ago

Thanks. This one works.


2 years ago

no problem!


Loading...