Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Why aren't the environment variables working inside my Django Docker container?

$
0
0

I'm encountering an issue where Django doesn't seem to be reading environment variables when running in a Docker-compose environment. Strangely, the environment variables work fine for PostgreSQL but not for Django. I've tried both the env_file and environment options in my Docker-compose file, and I've also experimented with django-dotenv without success.

Here's a snippet of my code:

print(f"{os.environ.get('SECRET_KEY')}{os.environ.get('DEBUG')}{os.environ.get('DATABASE_NAME')} ")# The above print statement outputs None for all environment variablesSECRET_KEY = os.environ.get("SECRET_KEY")# ...
version: '3.9'services:  db:    # ...   web:    build: ./src    command: gunicorn myapp.wsgi:application --access-logfile /logs/gunicorn/access.log --error-logfile /logs/gunicorn/error.log --bind 0.0.0.0:8000    volumes:      # ...    # env_file:  #not working    #   - .env    environment:      - SECRET_KEY=${SECRET_KEY}      - DATABASE_NAME=${DATABASE_NAME}      # ... (other environment variables)  nginx:    # ...
SECRET_KEY=3df-81ioo^5cx(p9cl$)s%m3mlu3t7*yh#1lr5h0po4_sab3*5DATABASE_NAME=mydbDATABASE_USER=postgresDATABASE_PASS=postgresDATABASE_HOST=dbDATABASE_PORT=5432DEBUG=0

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>