Build Containerized
Applications Using Docker and
Azure
Hamida Rebaï
Cloud Solution Architect - Microsoft MVP – Microsoft MCT – Docker Captain
@rebaihamida
JUNE 4 - 9, 2023 | #AGILEDEVOPSCON
LAS VEGAS, NV + ONLINE
M
i
c
r
o
s
o
f
t
M
V
P
Microsoft MVP &
MCT
SoftwareArchitect
Cloud Solutions Architect
Microsoft MVP in Developer Technologies
Member and Speaker at dotnetfoundation
Blogger and Technical writer
Book Author
Docker Captain
Rebai Hamida – Medium
Hamida Rebai Trabelsi | LinkedIn
Rebaï Hamida – YouTube
@rebaihamida
Table of content
• Microservices architecture
• Containers and Docker
• Overview Docker container and image
• Dockerfile
• Setting up Your Development Environment
• Containers in Azure
• Demos
Microservices architecture
• Model approach for distributed and large or complex critical
applications that are based on multiple, independent subsystems in the
form of autonomous services.
• Application is built as a collection of services car be developed, tested,
versioned, deployed, and scaled.
https://microservices.io/
Microservices ≠ Container
Containers and Docker
Docker Host
App 1 App 2
Service 1 Service 2
OS on a VM or a Server
Overview Docker container and image
Docker Container
● Virtualized runtime environment used
in application development.
● Can use just one machine, share its
kernel and virtualize the OS to run
more isolated processes.
● Docker containers are lightweight.
Docker Images
● Snapshot in other types of VM
environments.
● Record of a Docker container at a specific
point in time.
● Image can’t be changed, it can be
duplicated, shared, or deleted.
Container and image
Dockerfile Docker Image
Docker Container
Build Run
Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
1
COPY ["mysolution.csproj", « mysolution/"]
RUN dotnet restore « mysolution.csproj" 2
COPY . .
WORKDIR "/src/mysolution"
RUN dotnet build “mysolution.csproj" -c Release -o /app/build
3
Specify image
Copy project file
Copy and Build
Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
COPY --from=build /app/publish .
4
Dockerfile
Starting the app
5
ENTRYPOINT ["dotnet", « yousolution.dll"]
Build our image & start container
docker build -t yoursolutionimage:1.0 .
Create and run our container
docker run –d -p 8080:80 -ti –name myapp --rm yousolutionimage:1.0
To optimize publish
Use : -no-restore and p:PublishTrimmed, p:PublishReadyToRun,
p:PublishSingleFile
Containers Deployment
(Monolithic applications)
Legacy
Prerequisites
• Install Docker Desktop it is free, it is available for Mac and Windows.
• Docker Hub account, it is free.
• Install Visual Studio 2019 or 2022 or Visual Studio Code.
• Azure account where we are able to create an azure container registry
• PowerShell in Windows or Azure Cloud Shell.
• If you are using Visual Studio Code, Microsoft C# for Visual Studio Code,
Docker and Azure App Service extensions must be installed.
Demonstration flow
Tag the image locally
Using Visual Studio or
Docker command line
Azure Container registry is a private registry
Docker Hub to host public images
Azure Container Apps
Building a Docker Image Tagging Images Build and Store Images in the
Cloud
Demo: Building a Docker Image
Demo: Tagging an Image
Containers in Azure: a complete Set of Choices
Container Instances Batch
Service Fabric Kubernetes Service
App Service
PaaS vs CaaS vs FaaS
PaaS et CaaS
Azure Service Fabric
CaaS
Azure Container Instance
Azure Container App
Azure Kubernetes Service
FaaS
Azure Functions
1 2 3
Container and Orchestrator
Store
• Azure Container Instance
• Azure App Service as a
Container
• Azure Container Registry
For Multiple containers
For single container
• Azure Kubernetes Service
• Azure Container App
Azure Container Registry
Build and store images by using Azure Container
Registry
• What is Container Registry?
• Azure service that you can use to create your own private Docker
registries.
• Similar to Docker Hub but offers a few unique benefits: Container
Registry runs in Azure, Container Registry is highly scalable, providing
enhanced throughput for Docker pulls that can span many nodes
concurrently.
• Use Container Registry
• Create a registry by using either the Azure portal or the Azure CLI.
• Store and host images, and build images.
>_
Create an ACR with Azure CLI
az acr create --resource-group dockersamplerg --
name acrdemoapp --sku Basic --admin-enabled true
Build and Store Images by Using
Azure Container Registry (ACR)
Azure Kubernetes Services
Azure Kubernetes Services
• Azure Kubernetes Service (AKS) is a managed Kubernetes service that
lets you quickly deploy and manage clusters.
>_
Create AKS cluster using Azure CLI
az aks create --resource-group aksgr --name
myAKSCluster --node-count 1 -- generate-ssh-keys --
attach-acr aksprojectcontainer
Deploy an Azure Kubernetes Service cluster and run an
application using the Azure CLI
1- Open CloudShell My Dashboard — Microsoft Azure and connect to your cluster as
bellow:
az account set — subscription yoursubscription
az aks get-credentials — resource-group aksgr — name myAKSCluster
You can find these commands when you open Azure Portal and your cluster:
Deploy an Azure Kubernetes Service cluster and run an
application using the Azure CLI
• 2- Create an empty file called: azure-demo-deployment.yaml
• 3- Copy this content to the empty file created, we will describe it after.
Deploy an Azure Kubernetes Service cluster and run an
application using the Azure CLI
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-kubernetes-deployment
spec:
selector:
matchLabels:
app: demo-kubernetes-pod
replicas: 1
template:
metadata:
labels:
app: demo-kubernetes-pod
spec:
containers:
-- name: aksprojectcontainer
image:
aksprojectcontainer.azurecr.io
/aksproject:latest
ports:
-- containerPort: 80
Deploy an Azure Kubernetes Service cluster and run an
application using the Azure CLI
4- Run the application and deploy it in the cluster using the kubectl apply
command and specify the name of your YAML manifest.
kubectl apply -f azure-demo-deployment.yaml
We will use kubectl get deployments to verify if the deployment was
created or not.
When the application runs, a Kubernetes service exposes the application
front end to the internet. This process can take a few minutes to complete.
5- we will use kubectl get service command with the --watch argument.
kubectl get service demo-kubernetes-deployment — watch
Azure Container Apps
Azure Container App
Azure Container Apps is a fully managed environment that enables
you to run microservices and containerized applications on a
serverless platform.
• Provide a serverless hosting service that sits on top of an AKS Service
• Deploy multiple containers
• Azure Container app do not even expose Kubernetes APIs to the users.
Build containerized application using Docker and Azure.pdf

Build containerized application using Docker and Azure.pdf

  • 1.
    Build Containerized Applications UsingDocker and Azure Hamida Rebaï Cloud Solution Architect - Microsoft MVP – Microsoft MCT – Docker Captain @rebaihamida JUNE 4 - 9, 2023 | #AGILEDEVOPSCON LAS VEGAS, NV + ONLINE
  • 2.
    M i c r o s o f t M V P Microsoft MVP & MCT SoftwareArchitect CloudSolutions Architect Microsoft MVP in Developer Technologies Member and Speaker at dotnetfoundation Blogger and Technical writer Book Author Docker Captain Rebai Hamida – Medium Hamida Rebai Trabelsi | LinkedIn Rebaï Hamida – YouTube @rebaihamida
  • 3.
    Table of content •Microservices architecture • Containers and Docker • Overview Docker container and image • Dockerfile • Setting up Your Development Environment • Containers in Azure • Demos
  • 4.
    Microservices architecture • Modelapproach for distributed and large or complex critical applications that are based on multiple, independent subsystems in the form of autonomous services. • Application is built as a collection of services car be developed, tested, versioned, deployed, and scaled. https://microservices.io/
  • 5.
  • 6.
    Containers and Docker DockerHost App 1 App 2 Service 1 Service 2 OS on a VM or a Server
  • 7.
    Overview Docker containerand image Docker Container ● Virtualized runtime environment used in application development. ● Can use just one machine, share its kernel and virtualize the OS to run more isolated processes. ● Docker containers are lightweight. Docker Images ● Snapshot in other types of VM environments. ● Record of a Docker container at a specific point in time. ● Image can’t be changed, it can be duplicated, shared, or deleted.
  • 8.
    Container and image DockerfileDocker Image Docker Container Build Run
  • 9.
    Dockerfile FROM mcr.microsoft.com/dotnet/sdk:7.0 ASbuild WORKDIR /src 1 COPY ["mysolution.csproj", « mysolution/"] RUN dotnet restore « mysolution.csproj" 2 COPY . . WORKDIR "/src/mysolution" RUN dotnet build “mysolution.csproj" -c Release -o /app/build 3 Specify image Copy project file Copy and Build Build runtime image FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base WORKDIR /app COPY --from=build /app/publish . 4
  • 10.
    Dockerfile Starting the app 5 ENTRYPOINT["dotnet", « yousolution.dll"] Build our image & start container docker build -t yoursolutionimage:1.0 . Create and run our container docker run –d -p 8080:80 -ti –name myapp --rm yousolutionimage:1.0 To optimize publish Use : -no-restore and p:PublishTrimmed, p:PublishReadyToRun, p:PublishSingleFile
  • 11.
  • 12.
    Prerequisites • Install DockerDesktop it is free, it is available for Mac and Windows. • Docker Hub account, it is free. • Install Visual Studio 2019 or 2022 or Visual Studio Code. • Azure account where we are able to create an azure container registry • PowerShell in Windows or Azure Cloud Shell. • If you are using Visual Studio Code, Microsoft C# for Visual Studio Code, Docker and Azure App Service extensions must be installed.
  • 13.
    Demonstration flow Tag theimage locally Using Visual Studio or Docker command line Azure Container registry is a private registry Docker Hub to host public images Azure Container Apps Building a Docker Image Tagging Images Build and Store Images in the Cloud
  • 14.
    Demo: Building aDocker Image
  • 15.
  • 16.
    Containers in Azure:a complete Set of Choices Container Instances Batch Service Fabric Kubernetes Service App Service
  • 17.
    PaaS vs CaaSvs FaaS PaaS et CaaS Azure Service Fabric CaaS Azure Container Instance Azure Container App Azure Kubernetes Service FaaS Azure Functions 1 2 3
  • 18.
    Container and Orchestrator Store •Azure Container Instance • Azure App Service as a Container • Azure Container Registry For Multiple containers For single container • Azure Kubernetes Service • Azure Container App
  • 19.
  • 20.
    Build and storeimages by using Azure Container Registry • What is Container Registry? • Azure service that you can use to create your own private Docker registries. • Similar to Docker Hub but offers a few unique benefits: Container Registry runs in Azure, Container Registry is highly scalable, providing enhanced throughput for Docker pulls that can span many nodes concurrently. • Use Container Registry • Create a registry by using either the Azure portal or the Azure CLI. • Store and host images, and build images.
  • 21.
    >_ Create an ACRwith Azure CLI az acr create --resource-group dockersamplerg -- name acrdemoapp --sku Basic --admin-enabled true
  • 22.
    Build and StoreImages by Using Azure Container Registry (ACR)
  • 23.
  • 24.
    Azure Kubernetes Services •Azure Kubernetes Service (AKS) is a managed Kubernetes service that lets you quickly deploy and manage clusters.
  • 25.
    >_ Create AKS clusterusing Azure CLI az aks create --resource-group aksgr --name myAKSCluster --node-count 1 -- generate-ssh-keys -- attach-acr aksprojectcontainer
  • 26.
    Deploy an AzureKubernetes Service cluster and run an application using the Azure CLI 1- Open CloudShell My Dashboard — Microsoft Azure and connect to your cluster as bellow: az account set — subscription yoursubscription az aks get-credentials — resource-group aksgr — name myAKSCluster You can find these commands when you open Azure Portal and your cluster:
  • 27.
    Deploy an AzureKubernetes Service cluster and run an application using the Azure CLI • 2- Create an empty file called: azure-demo-deployment.yaml • 3- Copy this content to the empty file created, we will describe it after.
  • 28.
    Deploy an AzureKubernetes Service cluster and run an application using the Azure CLI apiVersion: apps/v1 kind: Deployment metadata: name: demo-kubernetes-deployment spec: selector: matchLabels: app: demo-kubernetes-pod replicas: 1 template: metadata: labels: app: demo-kubernetes-pod spec: containers: -- name: aksprojectcontainer image: aksprojectcontainer.azurecr.io /aksproject:latest ports: -- containerPort: 80
  • 29.
    Deploy an AzureKubernetes Service cluster and run an application using the Azure CLI 4- Run the application and deploy it in the cluster using the kubectl apply command and specify the name of your YAML manifest. kubectl apply -f azure-demo-deployment.yaml We will use kubectl get deployments to verify if the deployment was created or not. When the application runs, a Kubernetes service exposes the application front end to the internet. This process can take a few minutes to complete. 5- we will use kubectl get service command with the --watch argument. kubectl get service demo-kubernetes-deployment — watch
  • 30.
  • 31.
    Azure Container App AzureContainer Apps is a fully managed environment that enables you to run microservices and containerized applications on a serverless platform. • Provide a serverless hosting service that sits on top of an AKS Service • Deploy multiple containers • Azure Container app do not even expose Kubernetes APIs to the users.