Skip to content

jodejode77/dockerizing-app

Repository files navigation

Django Polls App in Docker

Simple Django polls application with PostgreSQL, prepared for a Docker lab.

Services:

  • web - Django app
  • db - PostgreSQL

Main files:

  • Dockerfile
  • compose.yaml
  • .env.example
  • entrypoint.sh

Run

docker compose build
docker compose up -d

Open:

http://localhost:8000

Stop:

docker compose down

Verify

docker 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:

  • db is healthy
  • migrations were applied
  • static files were collected
  • the site returns HTTP/1.1 200 OK
  • the app runs as appuser
  • PostgreSQL contains polls_question and polls_choice

Create Polls

Create an admin user:

docker compose exec web python manage.py createsuperuser

Then open:

http://localhost:8000/admin

Add a Question and several Choice rows, then open:

http://localhost:8000

Lab Notes

  • Alpine images are used: python:3.9-alpine and postgres: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-cache and pip install --no-cache-dir

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors