Simple Django polls application with PostgreSQL, prepared for a Docker lab.
Services:
web- Django appdb- PostgreSQL
Main files:
Dockerfilecompose.yaml.env.exampleentrypoint.sh
docker compose build
docker compose up -dOpen:
http://localhost:8000
Stop:
docker compose downdocker compose ps
docker compose logs web --tail 100
curl.exe -I http://localhost:8000
docker compose exec web sh -c "id && whoami"
docker compose exec db psql -U appuser -d appdb -c "\dt"Check that:
dbishealthy- migrations were applied
- static files were collected
- the site returns
HTTP/1.1 200 OK - the app runs as
appuser - PostgreSQL contains
polls_questionandpolls_choice
Create an admin user:
docker compose exec web python manage.py createsuperuserThen open:
http://localhost:8000/admin
Add a Question and several Choice rows, then open:
http://localhost:8000
- Alpine images are used:
python:3.9-alpineandpostgres:16-alpine - configuration is passed through environment variables
- static files are stored in the named volume
static_data - database files are stored in the named volume
postgres_data - migrations run automatically in
entrypoint.sh - the app container runs as non-root user
appuser - cache is avoided with
apk add --no-cacheandpip install --no-cache-dir