Skip to content

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.

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

“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.”

  • 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
  • Advanced Swagger customization
  • Logging to files
  • Health check endpoints

Containerize the full application so it runs with a single command.

  1. Create a Dockerfile in the project root
  2. Build the Docker image locally: docker build -t booksapi .
  3. Create a docker-compose.yml with two services: postgres and api
  4. Configure environment variables in docker-compose for the database connection string
  5. Add a health check on the postgres service so the API waits for it to be ready
  6. Add code to auto-apply EF Core migrations when the app starts
  7. Run docker-compose up and verify the API is accessible at http://localhost:5000
  8. Test endpoints in Swagger running inside Docker
  9. Add .WithDescription() and .WithTags() to a few key endpoints
  10. Write a README.md explaining how to clone and run the project
Terminal window
docker-compose up # Start everything (shows logs)
docker-compose up -d # Start in background
docker-compose down # Stop everything
docker-compose down -v # Stop and delete database volume (fresh start)
docker-compose logs -f api # Follow logs from the API container
  • Dockerfile structure (build stage vs runtime stage)
  • docker-compose.yml services, ports, and environment variables
  • depends_on with 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

docker-compose up starts everything. API is reachable at http://localhost:5000. Swagger has endpoint descriptions.


Week 7: Testing | Back to Overview | Capstone Project