Skip to content

Latest commit

 

History

History
335 lines (206 loc) · 5.89 KB

File metadata and controls

335 lines (206 loc) · 5.89 KB

1️⃣ Project Overview Questions

Q: What does this project do?

Answer idea

This project Dockerizes a Django blog application with a PostgreSQL database. The application is containerized using a multi-stage Dockerfile and orchestrated using Docker Compose. The stack includes Django, Gunicorn, and PostgreSQL, with environment-based configuration and persistent database storage.


Q: Why did you use Docker for this project?

Expected answer:

  • consistent environment
  • easy deployment
  • isolation
  • portability
  • reproducible builds

Example answer:

Docker ensures the application runs consistently across environments. It packages the application code, dependencies, and runtime configuration into an image that can be deployed anywhere without worrying about local environment differences.


2️⃣ Dockerfile Questions

Q: Why did you use a multi-stage build?

Expected answer:

  • smaller images
  • separation of build and runtime

Example:

The builder stage installs dependencies, while the runtime stage contains only the application and installed packages. This reduces the final image size and improves security by removing build tools from the runtime image.


Q: Why use python:slim instead of full python image?

Expected answer:

  • smaller image
  • fewer unnecessary packages
  • faster downloads

Q: What is .dockerignore and why is it important?

Expected answer:

  • prevents unnecessary files from being copied
  • reduces build context size
  • speeds up build
  • prevents secrets from being included

Example:

.git
venv
__pycache__
.env

3️⃣ Container Runtime Questions

Q: Why use Gunicorn instead of python manage.py runserver?

Expected answer:

  • runserver is for development
  • Gunicorn is production-grade WSGI server
  • supports multiple workers
  • better performance

Example answer:

Django's runserver is not optimized for production workloads. Gunicorn is a production WSGI server that can handle concurrent requests using worker processes.


Q: Why run the container with a non-root user?

Expected answer:

security.

Example answer:

Running containers as root can be dangerous because if an attacker exploits the application they could gain root access inside the container. Using a non-root user limits the permissions and reduces the attack surface.


4️⃣ Docker Compose Questions

Q: What does Docker Compose do?

Expected answer:

Docker Compose allows defining and running multi-container applications using a single YAML configuration file.

In your project it orchestrates:

Django container
PostgreSQL container
Network
Volumes
Environment variables

Q: Why did you use a custom network?

Expected answer:

It allows containers to communicate using service names. In this project the Django container connects to the database using the hostname db.

Example:

DB_HOST=db

Q: Why did you use a volume for Postgres?

Expected answer:

Containers are ephemeral. If the database container stops, data would be lost without persistent storage. The volume ensures database data survives container restarts.


5️⃣ Database & Migration Questions

Q: What are migrations?

Expected answer:

Migrations track database schema changes and apply them incrementally.

Example:

add column
create table
rename field

Q: Why do we run python manage.py migrate?

Expected answer:

It applies pending migration files and updates the database schema to match the Django models.


Q: Why should DevOps not run makemigrations in production?

Expected answer:

Because migrations should be created by developers and committed to version control.

Production should only run:

migrate

6️⃣ Environment Variables Questions

Q: Why use .env instead of hardcoding variables?

Expected answer:

  • separates config from code
  • security
  • environment-specific configs

Example:

dev
staging
production

7️⃣ Docker Hub Questions

Q: Why push the image to Docker Hub?

Expected answer:

Docker Hub acts as a container registry where images can be stored and pulled from any machine or deployment system.

Deployment flow:

build image
push to registry
pull on server
run containers

8️⃣ Debugging Questions

Q: If the container shows 500 error, how do you debug?

Possible steps:

1️⃣ check logs

docker logs container

2️⃣ check migrations

python manage.py showmigrations

3️⃣ inspect database

psql
\dt

4️⃣ exec into container

docker exec -it container bash

9️⃣ Scaling Question

Q: What happens if you run multiple Django containers?

Possible issues:

  • migrations running multiple times
  • database locks

Solutions:

  • run migrations as a separate job
  • CI/CD migration step
  • leader election

10️⃣ Advanced DevOps Questions

Q: How would you deploy this in Kubernetes?

Expected answer:

  • Deployment for Django
  • StatefulSet for PostgreSQL
  • PersistentVolume for DB
  • ConfigMaps for environment variables
  • Job for migrations

Q: How would you add zero downtime deployments?

Possible answers:

  • rolling updates
  • health checks
  • load balancer
  • blue-green deployments

11️⃣ Security Improvements

Possible improvements:

  • use secrets manager
  • avoid .env in production
  • enable TLS
  • scan images
  • use minimal base images

12️⃣ Best Question You Can Ask

Shows maturity:

In production environments do you run database migrations during container startup or as part of the CI/CD pipeline?

This shows you understand real-world deployment problems.


Big Picture

This single project demonstrates knowledge of:

Docker
Container builds
Multi-stage images
Docker Compose
Networking
Volumes
Database migrations
Environment configuration
Production WSGI servers
Debugging containers