How to run a local project in live configuration¶
The Local, Test and Live server environments are as identical as possible, to help guarantee that your applications will run in just the same way across all of them.
However, there are a few differences. See Default project conditions for the default configuration in each environment.
Occasionally, you may wish to run the local server in a configuration closer to the live set-up. A few steps are needed to achieve this.
Build the project¶
Build the project in the normal way (
docker-compose build web) if there have been any changes to it.
volumes behaviour in
Dockerfile includes commands that mean that files in the project are processed at build time (say,
processing of static files before collection), the default volumes configuration in the docker-compose.yml file will cause this to be overwritten at run-time.
In such a case, comment out the line:
docker-compose.yml. Note that this means that further
changes you make to the project files on your host system will not be reflected inside the container until the
line is restored and the project restarted.
Turn off Django
Set a couple of environment variables in the file
Collect static files¶
Gather static files to be served, using
docker-compose run --rm web python manage.py collectstatic
docker-compose run --rm web start migrate
This runs the commands listed in the
MIGRATION_COMMANDS setting, populated by applications using the addons
framework, that are executed in Cloud deployments.
Use the production web server¶
Use the production web server (using uWSGI, and serving static files) rather than the Django runserver. In the docker-compose.yml file, change:
command: python manage.py runserver 0.0.0.0:80
command: start web
Now when you start the local server, it will behave more like the live server.