I have a Django project and I'm trying to deploy it on an AWS EC2 instance.
I've created 2 docker images (application and nginx), tested locally, pushed to hub, but when I pull in my EC2 instance and try to run it, I'm getting environment variable errors like this one:
File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 90, in __getattr__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I've tried to create the .env file in the root folder and run:
docker run <image_id> --env-file ./.env
Also tried to set the varible manually with:
expose MY_VAR='something'
Still not working.
Is there a specific way to run images that was created and pushed with docker-compose, setting the environment variables?
David Maze's comment solved my problem. Basically was the command syntax:
docker run --env-file ./.env <image_id>