I created a docker machine on EC2.
Then I created a new cookiecutter-django app and left it plain vanilla. It's set to use .env for the environment variables. (Cookiecutter-django includes django-environ for accessing environment variables.)
docker-compose -f production.yml build
worked fine.
docker-compose -f production.yml up
gives this error:
django_1 | botocore.exceptions.ParamValidationError: Parameter validation failed:
django_1 | Invalid bucket name "": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$"
Researching this error, the advise was setting various environment variables. So I've tried them all in the .env (I did create an s3 bucket named pulsemanager):
DJANGO_AWS_STORAGE_BUCKET_NAME=pulsemanager
AWS_S3_BUCKET_NAME_STATIC=pulsemanager
AWS_STORAGE_BUCKET_NAME=pulsemanager
No matter what I try I'm stuck with the error.
EDIT: It's not exactly plain vanilla. By default cookiecutter-django is using the Caddy http server instead of nginx in docker. That includes SSL and won't work behind an AWS load balancer with an AWS certificate manager SSL. So I did change the default production.yml to bring in nginx instead of Caddy, following this article.
Do you have a mistake in the environment filename? You wrote "evn" twice in your question when correct is ".env" https://docs.docker.com/compose/env-file/ .
Also, this environment variables will be available for Docker-compose file only. It means, if you need to pass this vars to particular container, you need to use environment:
section for pass this vars to container, like this:
app:
- environment:
DJANGO_AWS_STORAGE_BUCKET_NAME=${DJANGO_AWS_STORAGE_BUCKET_NAME}
Also, you can pass all vars from the .env file, by using env_file:
for particular container: https://docs.docker.com/compose/environment-variables/#the-env_file-configuration-option
app:
env_file:
- .env
If you have a correct configured containers and environment variables you can debug your vars by connecting to a container and check if vars was passed.
docker exec -ti CONTAINER_ID /bin/export
Also, possible you need to add configuration to your django settings.py file. For example:
import os
DJANGO_AWS_STORAGE_BUCKET_NAME=os.environ.get('DJANGO_AWS_STORAGE_BUCKET_NAME')