Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

500
Vistas
Docker-compose (and django): Can't get environment variables onto the services

I'm trying to write a small docker(-compose) deployment solution for a small Django application.

Currently, the django-compose file, named docker-compose.dev.yaml looks something like this:

version: "3"

services:
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - 8000:8000
    env_file:
      - dev.env

The file dev.env looks like this:

DEBUG=1
SECRET_KEY=We9ZyuSKsP9Mgvsrt74gExF8baWbGL # not important that this leaks
DJANGO_ALLOWED_HOSTS=localhost

However, when django tries to start, I get the following:

#11 0.634 ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")

#11 0.634 AttributeError: 'NoneType' object has no attribute 'split'

Basically, the environment variable is returning None, meaning the variables aren't getting onto the container.

I tried, according to the docs, to do this:

    # ...
    environment:
      - DEBUG
      - SECRET_KEY
      - DJANGO_ALLOWED_HOSTS

Without any luck.

Any ideas? The repository behind the code is public, I invite you to try.

My current test environment is Docker desktop on Windows 10.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

So, I figured it out.

Turns out that this line in the Dockerfile for the backend:

RUN python manage.py migrate

Was the problem. I didn't realize it ran at build time, not at runtime, so the environment variables weren't available.

I moved into a script called at runtime and not it all works!

backend/Dockerfile:

# ...
# Make files executable
RUN chmod +x start.dev.sh

backend/start.dev.sh:

#!/bin/bash
python manage.py migrate
python manage.py runserver 0.0.0.0:8000

And ./docker-compose.dev.yaml:

# ...
    command: ./start.dev.sh
# ...
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda