My goal is to run collectstatic
command inside Dockerfile
, but when trying to rebuild and run the container by running
docker-compose up -d --build
I run into KeyError
messages coming from settings.py
file on lines where environmental variables are used, for example:
os.environ['CELERY_BROKER']
This is apparently because the container is not yet built, so Docker does not know anything about the environment variables defined in my .env
file. Is there any command to import all the variables to Docker?
Or maybe it's a bad idea to run the collectstatic
command inside Dockerfile and it should be run inside docker-compose file ? Or maybe as part of a CI/CD task ?
My Dockerfile looks like this:
COPY . /app/
WORKDIR /app
RUN python manage.py collectstatic --noinput
RUN ls -la