Django failed in build. Not found in env
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 <module> SECRET_KEY = env("DJANGO_SECRET_KEY") ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/environ/environ.py", line 199, in call return self.get_value( ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/environ/environ.py", line 392, in get_value raise ImproperlyConfigured(error_msg) from exc django.core.exceptions.ImproperlyConfigured: Set the DJANGO_SECRET_KEY environment variableI already put the variables in the project
Solution:Jump to solution
either way, please see this docs section - https://docs.railway.app/guides/dockerfiles#using-variables-at-build-time
16 Replies
Project ID:
3995ec84-e5e8-447a-bc3d-a110c9b3e381
please attach the dockerfile as a file
3995ec84-e5e8-447a-bc3d-a110c9b3e381
you have your environment variable named incorrectly
Sorry i think on the above i paste the error message wrongly
where is this env function defined?
in Dockerfile
in my django settings
im sorry im not sure how that answered the question?
Solution
either way, please see this docs section - https://docs.railway.app/guides/dockerfiles#using-variables-at-build-time
okay i try follow this one first
Thanks. This one works.
no problem!