Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Azure Saturday Hamburg: Containerize Your .NET Microservice - the Right Way!

Every time we start a new project or learn a new technology, we're looking for zero to hero guides to help us get started quickly and easily. In most cases, however, these guidelines are not intended to be production-ready and secure.
Join Nico and dive into the secrets and best practices of how to create fast, secure and production-ready Dockerfiles for your .NET Microservice.
Walk away and learn everything you need to take your container builds to the next level.

  • Sé el primero en comentar

  • Sé el primero en recomendar esto

Azure Saturday Hamburg: Containerize Your .NET Microservice - the Right Way!

  1. 1. Containerize Your .NET Microservice - the Right Way! Azure Saturday Hamburg 2021
  2. 2. Nico Meisenzahl • Senior Cloud & DevOps Consultant at white duck • Microsoft MVP, GitLab Hero & Docker Community Leader • Container, Kubernetes & Cloud-Native © white duck GmbH 2021 Phone: +49 8031 230159 0 Email: nico.meisenzahl@whiteduck.de Twitter: @nmeisenzahl LinkedIn: https://www.linkedin.com/in/nicomeisenzahl Blog: https://meisenzahl.org
  3. 3. Agenda • All about the Dockerfile • The .NET base images • Container / Microservices Design patterns © white duck GmbH 2021
  4. 4. ALL ABOUT THE DOCKERFILE © white duck GmbH 2021
  5. 5. A Dockerfile story • microservices is based on ASP.NET Core 5.0 • most is the same for ASP.NET Core 3.x • linux-only • you will see anti-patterns (keep this in mind)! • they are indicated with an orange bubble © white duck GmbH 2021
  6. 6. © white duck GmbH 2021
  7. 7. © white duck GmbH 2021
  8. 8. © white duck GmbH 2021
  9. 9. A good starting point • define image tags • use small images if possible (Alpine, Debian-slim) • multi-stage builds • think about your layers • use dotnet restore and dotnet publish • do not run as root © white duck GmbH 2021
  10. 10. Smaller, smaller, smaller • 75 MB instead of 125 MB (including a small app) • not the best option for most use-cases • smaller images size but bigger layer changes • self-contained and trimmed binary • smallest possible base image © white duck GmbH 2021
  11. 11. THE .NET BASE IMAGES © white duck GmbH 2021
  12. 12. Base images • documentation and tags are available on Docker Hub • https://hub.docker.com/_/microsoft-dotnet/ • https://hub.docker.com/_/microsoft-dotnet-framework/ • images are distributed via mcr.microsoft.com • https://mcr.microsoft.com/v2/_catalog/ • https://mcr.microsoft.com/v2/dotnet/xxx/tags/list © white duck GmbH 2021
  13. 13. Base images • Dockerfiles and more details are on GitHub (open-source) • https://github.com/dotnet/dotnet-docker • News & announcements • https://github.com/dotnet/announcements/labels/Docker © white duck GmbH 2021
  14. 14. .NET (Core) base images • mcr.microsoft.com/dotnet/sdk • mcr.microsoft.com/dotnet/aspnet • mcr.microsoft.com/dotnet/runtime • mcr.microsoft.com/dotnet/runtime-deps • nightly builds • https://hub.docker.com/_/microsoft-dotnet-nightly/ • mcr.microsoft.com/dotnet/nightly/xxx © white duck GmbH 2021
  15. 15. .NET (Core) base images platforms • available OS versions on amd64 • Debian 9 / 10 • Ubuntu 18.04 / 20.04 • Alpine 3.12 / 3.13 • Nano Server 20H2 / 2004 / 1909 / 1809 • Windows Server Core 2019 • available OS versions on arm64v8 & arm32v7 • Debian 9 (arm32v7 only) / 10 • Ubuntu 18.04 / 20.04 © white duck GmbH 2021
  16. 16. Example: ASP.NET Core tags for amd64 on Linux © white duck GmbH 2021
  17. 17. New location for .NET (Core) images • all linux-based images (including 2.x, 3.x and 5.x) got moved to a new repo • old: mcr.microsoft.com/dotnet/core/xxx • new: mcr.microsoft.com/dotnet/xxx • update your existing Dockerfiles! © white duck GmbH 2021
  18. 18. .NET Framework base images • available base images • mcr.microsoft.com/dotnet/framework/sdk • mcr.microsoft.com/dotnet/framework/aspnet • mcr.microsoft.com/dotnet/framework/runtime • mcr.microsoft.com/dotnet/framework/wcf • Windows Server Core only © white duck GmbH 2021
  19. 19. CONTAINER/MICROSERVICES DESIGN PATTERNS © white duck GmbH 2021
  20. 20. General image build best practices • add a .dockerignore file to your repo • use multi-stage builds and reduce layers (but not for any price) • use BuildKit or any other modern solution to speed up your build • Azure Container Registry (ACR) image builds can reduce dependencies on your build machine (CI/CD) • and many more • https://docs.docker.com/develop/develop-images/dockerfile_best- practices © white duck GmbH 2021
  21. 21. 12-Factor App • defines 12 important factors to build solid microservices • https://12factor.net • a few examples • store config in envs (AddEnvironmentVariables) • export services via port binding • execute the app as one (or more) stateless processes • maximize robustness with fast startup and graceful shutdown • run admin/management tasks as one-off processes © white duck GmbH 2021
  22. 22. Container Design patterns • write application logs to STDOUT (AddConsole) • provide liveness, readiness endpoints (AddHealthChecks) • Init-container, side-car, ambassador pattern • think about • distributed tracing • retries • circuit breakers • … © white duck GmbH 2021
  23. 23. Questions? • Slides • https://www.slideshare.net/nmeisenzahl • Blog post • https://medium.com/01001101/containerize-your-net-core-app-the-right- way-35c267224a8d © white duck GmbH 2021

×