Test the AWS setup locally¶
Use docker-compose-aws.yml to build and run the production Docker image on your local machine before deploying to AWS. This exercises Dockerfile-aws, entrypoint-aws.sh, and settings_aws.py — catching configuration issues early.
The app runs on port 8001 so it can coexist with the standard dev environment on port 8000.
Set up¶
-
Copy the example env file
-
Edit
.env.docker-awsand set a realSECRET_KEY— don't leave the placeholder value -
Build and start the containers
The build runs
collectstaticand the entrypoint runsmigrateautomatically on startup. -
Verify it's running correctly
- Browse to
http://localhost:8001/admin/— you should see the Django admin login page (not a 500 or connection error), styled with CSS (not unstyled HTML — confirmscollectstatic/whitenoise are working) curl http://localhost:8001/api/v1/should return a JSON response, not a 404 or 500http://localhost:8001/api/schema/swagger-ui/should 404(Not Found) —urls_aws.pyintentionally excludes schema routes from production
- Browse to
-
Create a superuser to log into the admin interface (in a separate terminal)
Logging in successfully at
http://localhost:8001/admin/confirms migrations ran and the database is up.
Stop and clean up¶
To also remove the database volume:
Network warning
You may see ! Network peopledepot_default Resource is still in use — this is harmless. The containers and volume are already removed. The network is shared with the dev docker-compose.yml stack (the mkdocs container keeps it alive) and will clean up when that stack is stopped.
Gotchas¶
Warning
requirements-aws.txtmust be compiled with--python-version 3.10— compiling locally can resolve packages incompatible with the Docker image's Python version- Do not mount
./app/as a volume — it would bypasscollectstatic, the multi-stage build, andsettings_aws.py .env.docker-awssetsSECURE_SSL_REDIRECT=False; real production sets itTrue. Don't flip it toTruelocally — without SSL it causes an infinite redirect loopdrf_spectacularstays inrequirements-aws.txteven though it's excluded fromINSTALLED_APPS— it's still a runtime import inviews.pydecorators, and the container crashes without itDEBUG=Falseis intentional — don't change it; the point of this setup is to test production behavior
Differences from the standard dev environment¶
docker-compose.yml |
docker-compose-aws.yml |
|
|---|---|---|
| Image | Dev (Dockerfile) |
Production (Dockerfile-aws) |
| Server | Django runserver |
gunicorn |
| Settings | settings.py |
settings_aws.py |
| Dependencies | requirements.txt |
requirements-aws.txt |
| App port | 8000 | 8001 |
| DB port | 5432 | 5433 |
| DB volume | postgres_data |
postgres_data_aws |
| Code reloading | Yes (volume mount) | No (baked into image) |
| Schema UI | Available | Excluded (urls_aws.py) |