SlideShare a Scribd company logo
Containerize Your .NET Microservice - the
Right Way!
Azure Saturday Hamburg 2021
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
Agenda
• All about the Dockerfile
• The .NET base images
• Container / Microservices Design patterns
© white duck GmbH 2021
ALL ABOUT THE DOCKERFILE
© white duck GmbH 2021
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
© white duck GmbH 2021
© white duck GmbH 2021
© white duck GmbH 2021
Azure Saturday Hamburg: Containerize Your .NET Microservice - the Right Way!
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
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
Azure Saturday Hamburg: Containerize Your .NET Microservice - the Right Way!
THE .NET BASE IMAGES
© white duck GmbH 2021
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
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
.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
.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
Example: ASP.NET Core tags for amd64 on Linux
© white duck GmbH 2021
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
.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
CONTAINER/MICROSERVICES DESIGN
PATTERNS
© white duck GmbH 2021
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
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
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
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

More Related Content

PDF
Die Evolution von Container Image Builds
PDF
Hijack a Kubernetes Cluster - a Walkthrough
PDF
azdevcom - Hijack a Kubernetes Cluster
PDF
Continuous Lifecycle: Hijack Kubernetes
PDF
GitLab Commit: Your Attackers Won't Be Happy! How GitLab Can Help You Secure ...
PDF
Continuous Lifecycle: Enhance Your Compliance and Governance With Policy-Base...
PDF
Policy & Governance für Kubernetes
PDF
Azure Meetup Hamburg: Production-Ready Terraform Deployments on Azure
Die Evolution von Container Image Builds
Hijack a Kubernetes Cluster - a Walkthrough
azdevcom - Hijack a Kubernetes Cluster
Continuous Lifecycle: Hijack Kubernetes
GitLab Commit: Your Attackers Won't Be Happy! How GitLab Can Help You Secure ...
Continuous Lifecycle: Enhance Your Compliance and Governance With Policy-Base...
Policy & Governance für Kubernetes
Azure Meetup Hamburg: Production-Ready Terraform Deployments on Azure

What's hot (20)

PDF
Azure Rosenheim Meetup: Azure Service Operator
PDF
GitLab Commit DevOps: How GitLab Can Save your Kubernetes environment from Be...
PDF
GitHub Actions 101
PDF
Cloud Native Day: Cloud-native Anwendungsentwicklung im Jahr 2021
PDF
DevOpsCon Berlin: Helm vs Operators – Do I Need to Decide?
PDF
Azure Zürich User Group: Azure Kubernetes Service – more than just a managed ...
PDF
GitLab Commit: Enhance your Compliance with Policy-Based CI/CD
PDF
Was ist ein Service Mesh und wie funktioniert es?
PDF
GitLab Remote Meetup: Enhance Your Kubernetes CI/CD Pipelines with GitLab & ...
PPTX
FestiveTechCalendar2021 - Have Yourself An​ Azure Container Registry
PDF
The Future of Workflow Automation Is Now - Hassle-Free ARM Template Deploymen...
PDF
Global Azure Bootcamp: Container, Docker & Kubernetes Basics
PDF
Virtual Azure Community Day: Azure Kubernetes Service Basics
PDF
DevOps Gathering - How Containerized Pipelines Can Boost Your CI/CD
PDF
DevOpsCon London: How containerized Pipelines can boost your CI/CD
PPTX
Securing your Cloud Environment v2
PDF
Create A Mapping Web Part
PDF
Image scanning using Clair
PDF
KCD Guatemala - Abstracciones sobre Abstracciones
PDF
Developing and Deploying Microservices with Project Tye
Azure Rosenheim Meetup: Azure Service Operator
GitLab Commit DevOps: How GitLab Can Save your Kubernetes environment from Be...
GitHub Actions 101
Cloud Native Day: Cloud-native Anwendungsentwicklung im Jahr 2021
DevOpsCon Berlin: Helm vs Operators – Do I Need to Decide?
Azure Zürich User Group: Azure Kubernetes Service – more than just a managed ...
GitLab Commit: Enhance your Compliance with Policy-Based CI/CD
Was ist ein Service Mesh und wie funktioniert es?
GitLab Remote Meetup: Enhance Your Kubernetes CI/CD Pipelines with GitLab & ...
FestiveTechCalendar2021 - Have Yourself An​ Azure Container Registry
The Future of Workflow Automation Is Now - Hassle-Free ARM Template Deploymen...
Global Azure Bootcamp: Container, Docker & Kubernetes Basics
Virtual Azure Community Day: Azure Kubernetes Service Basics
DevOps Gathering - How Containerized Pipelines Can Boost Your CI/CD
DevOpsCon London: How containerized Pipelines can boost your CI/CD
Securing your Cloud Environment v2
Create A Mapping Web Part
Image scanning using Clair
KCD Guatemala - Abstracciones sobre Abstracciones
Developing and Deploying Microservices with Project Tye
Ad

Similar to Azure Saturday Hamburg: Containerize Your .NET Microservice - the Right Way! (20)

PPTX
Dockerization of Azure Platform
PPTX
Docker for a .NET web developer
PPTX
Docker containers on Windows
PDF
Docker for .NET Developers - Michele Leroux Bustamante, Solliance
PDF
Rome .NET Conference 2024 - Remote Conference
PDF
Net Microservices Architecture For Containerized Net Applications V60 Updated...
PPTX
Techdays SE 2016 - Micros.. err Microcosmos
PPTX
The Microservices world in. NET Core and. NET framework
PPTX
Micro Services in .NET Core and Docker
PDF
Net Microservices Architecture For Containerized Net Applications V70 Updated...
PPTX
Azure App Service for Windows Container
PPTX
Modernizing existing .NET applications with Windows Containers and Azure cloud
PPTX
Net core microservice development made easy with azure dev spaces
PDF
Advanced microservices with .Net
PDF
NET Microservices Architecture for Containerized NET Applications Cesar De La...
PPTX
DotnetConf - Cloud native and .Net5 announcements
PDF
Build containerized application using Docker and Azure.pdf
PPTX
Going MicroServices with Net
PPTX
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
PDF
Open source based container solution in Azure - May Docker Meetup
Dockerization of Azure Platform
Docker for a .NET web developer
Docker containers on Windows
Docker for .NET Developers - Michele Leroux Bustamante, Solliance
Rome .NET Conference 2024 - Remote Conference
Net Microservices Architecture For Containerized Net Applications V60 Updated...
Techdays SE 2016 - Micros.. err Microcosmos
The Microservices world in. NET Core and. NET framework
Micro Services in .NET Core and Docker
Net Microservices Architecture For Containerized Net Applications V70 Updated...
Azure App Service for Windows Container
Modernizing existing .NET applications with Windows Containers and Azure cloud
Net core microservice development made easy with azure dev spaces
Advanced microservices with .Net
NET Microservices Architecture for Containerized NET Applications Cesar De La...
DotnetConf - Cloud native and .Net5 announcements
Build containerized application using Docker and Azure.pdf
Going MicroServices with Net
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Open source based container solution in Azure - May Docker Meetup
Ad

More from Nico Meisenzahl (15)

PDF
Cloud-Native & Sustainability: How and Why to Build Sustainable Workloads
PDF
Container Day Security: How to Prevent Your Kubernetes Cluster From Being Hacked
PDF
Festive Tech Calendar: Festive time with AKS networking
PDF
ContainerConf 2022: Hijack Kubernetes
PDF
ContainerConf 2022: Kubernetes is awesome - but...
PDF
KCD Munich 2022: How to Prevent Your Kubernetes Cluster From Being Hacked
PDF
KCD Munich 2022: Hijack a Kubernetes Cluster - a Walkthrough
PDF
Cloud Love Conference: Kubernetes is awesome, but...
PDF
How to Prevent Your Kubernetes Cluster From Being Hacked
PDF
Container Days: Hijack a Kubernetes Cluster - a Walkthrough
PPTX
Hijack a Kubernetes Cluster - a Walkthrough
PDF
Hijack a Kubernetes Cluster - a Walkthrough
PDF
Microsoft DevOps Forum 2021 – DevOps & Security
PDF
Azure Service Operator - Provision Your Resources in a Cloud-Native Way
PDF
Effiziente CI/CD-Pipelines – mit den richtigen Tools klappt das
Cloud-Native & Sustainability: How and Why to Build Sustainable Workloads
Container Day Security: How to Prevent Your Kubernetes Cluster From Being Hacked
Festive Tech Calendar: Festive time with AKS networking
ContainerConf 2022: Hijack Kubernetes
ContainerConf 2022: Kubernetes is awesome - but...
KCD Munich 2022: How to Prevent Your Kubernetes Cluster From Being Hacked
KCD Munich 2022: Hijack a Kubernetes Cluster - a Walkthrough
Cloud Love Conference: Kubernetes is awesome, but...
How to Prevent Your Kubernetes Cluster From Being Hacked
Container Days: Hijack a Kubernetes Cluster - a Walkthrough
Hijack a Kubernetes Cluster - a Walkthrough
Hijack a Kubernetes Cluster - a Walkthrough
Microsoft DevOps Forum 2021 – DevOps & Security
Azure Service Operator - Provision Your Resources in a Cloud-Native Way
Effiziente CI/CD-Pipelines – mit den richtigen Tools klappt das

Recently uploaded (20)

PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
August Patch Tuesday
PPT
Teaching material agriculture food technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Spectroscopy.pptx food analysis technology
Heart disease approach using modified random forest and particle swarm optimi...
Per capita expenditure prediction using model stacking based on satellite ima...
A comparative study of natural language inference in Swahili using monolingua...
Group 1 Presentation -Planning and Decision Making .pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cloud_computing_Infrastucture_as_cloud_p
TLE Review Electricity (Electricity).pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
A comparative analysis of optical character recognition models for extracting...
OMC Textile Division Presentation 2021.pptx
August Patch Tuesday
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectroscopy.pptx food analysis technology

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

  • 1. Containerize Your .NET Microservice - the Right Way! Azure Saturday Hamburg 2021
  • 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. Agenda • All about the Dockerfile • The .NET base images • Container / Microservices Design patterns © white duck GmbH 2021
  • 4. ALL ABOUT THE DOCKERFILE © white duck GmbH 2021
  • 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. © white duck GmbH 2021
  • 7. © white duck GmbH 2021
  • 8. © white duck GmbH 2021
  • 10. 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
  • 11. 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
  • 13. THE .NET BASE IMAGES © white duck GmbH 2021
  • 14. 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
  • 15. 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
  • 16. .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
  • 17. .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
  • 18. Example: ASP.NET Core tags for amd64 on Linux © white duck GmbH 2021
  • 19. 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
  • 20. .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
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. 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