My docker-compose.yml:
version: '3.8'
services:
web:
build: ./app
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- ./app/:/usr/src/app/
ports:
- 8000:8000
env_file:
- .dev.env
my Dockerfile in ./app:
FROM kuralabs/python3-dev
WORKDIR /usr/src/app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip3 install -r requirements.txt
COPY . .
My file .dev.env:
ALLOWED_HOSTS='localhost 127.0.0.1'
DEBUG=1
SECRET_KEY='django-insecure-...'
I run the project with the commands:
$docker-compose build
$docker-compose up -d
I get variables in settings.py:
load_dotenv()
print(f'Environment: {os.environ}')
my variables from the '.dev.env' file are not in the list of environment variables.
Please help me understand why .dev.env variables don't get into the environment.

You can use environment variables from a .env file by assigning them to your service, take the following example
The environment variables are directly read from the
.envfile located next to the docker-compose.yaml. Note thatenv_filestill works the same way. So instead of reading from the.envfile, you can utilizeenv_fileto target (in your case) the.dev.envfile.Hope this helps.
In addition, perhaps you could assign the path of
load_dotenv.That should also work, when placed somewhere after your imports in
manage.py.