Week 8: Docker & Documentation
Containerize the full application so anyone can clone the repo and start everything with a single command. Add descriptions to Swagger so the API is self-documenting.
Essential (70% of time)
Section titled “Essential (70% of time)”Core skills:
- Write a Dockerfile for the API
- Write a docker-compose.yml that starts API and PostgreSQL together
- Run the full stack with
docker-compose up - Add basic descriptions to Swagger endpoints
Key resources
Section titled “Key resources”- Docker Compose Overview
- Docker Compose Getting Started
- Compose File Reference
- Containerize a .NET App
- Docker for .NET
- Dockerfile Best Practices
LLM prompts
Section titled “LLM prompts”“Create a docker-compose.yml for my .NET 8 API and PostgreSQL. Simplest version that works. Include environment variables for the database connection.”
“Show me a basic Dockerfile for my .NET 8 API.”
“How do I make my API wait for PostgreSQL to be ready before starting in Docker Compose?”
“Show me how to add a description and tag to a Swagger endpoint in a Minimal API. One example is enough.”
Brief (20% of time)
Section titled “Brief (20% of time)”- Add basic console logging using
ILogger - Write a README.md with setup and run instructions
- Auto-apply EF Core migrations on startup inside the container
Optional (skip if needed)
Section titled “Optional (skip if needed)”- Advanced Swagger customization
- Logging to files
- Health check endpoints
Practical project
Section titled “Practical project”Containerize the full application so it runs with a single command.
Learning activities
Section titled “Learning activities”- Create a
Dockerfilein the project root - Build the Docker image locally:
docker build -t booksapi . - Create a
docker-compose.ymlwith two services:postgresandapi - Configure environment variables in docker-compose for the database connection string
- Add a health check on the postgres service so the API waits for it to be ready
- Add code to auto-apply EF Core migrations when the app starts
- Run
docker-compose upand verify the API is accessible at http://localhost:5000 - Test endpoints in Swagger running inside Docker
- Add
.WithDescription()and.WithTags()to a few key endpoints - Write a README.md explaining how to clone and run the project
Useful Docker Compose commands
Section titled “Useful Docker Compose commands”docker-compose up # Start everything (shows logs)docker-compose up -d # Start in backgrounddocker-compose down # Stop everythingdocker-compose down -v # Stop and delete database volume (fresh start)docker-compose logs -f api # Follow logs from the API containerKey concepts to master
Section titled “Key concepts to master”- Dockerfile structure (build stage vs runtime stage)
- docker-compose.yml services, ports, and environment variables
depends_onwith a health check so the API waits for PostgreSQL- Passing connection strings via environment variables
- Auto-applying migrations on startup
- Running and stopping the full stack
Deliverable
Section titled “Deliverable”docker-compose up starts everything. API is reachable at
http://localhost:5000. Swagger has endpoint descriptions.