Deploying Containers, Binaries and Scripts
This lesson shows how pipelines deploy each form of software, and how they authenticate.
Learning outcomes
After completing this lesson, you will be able to:
- Build and deploy a container image.
- Explain run from package.
- Run scripts safely against Azure.
- Choose tasks and actions for each form.
Container deployments
A container image packages an application with everything it needs, so it runs in the same way on each host. A pipeline builds an image from a Dockerfile, pushes it to a registry such as Azure Container Registry, and then tells a host to run it. A multi-stage Dockerfile keeps images small by leaving build tools out of the final image.
# Azure Pipelines
- task: Docker@2
inputs:
containerRegistry: sc-acr
repository: web
command: buildAndPush
Dockerfile: Dockerfile
tags: |
$(Build.BuildId)
- task: KubernetesManifest@1
inputs:
action: deploy
connectionType: azureResourceManager
azureSubscriptionConnection: sc-azure-prod
azureResourceGroup: rg-aks
kubernetesCluster: aks-prod
manifests: k8s/deployment.yml
containers: contoso.azurecr.io/web:$(Build.BuildId)Azure Kubernetes Service (AKS) suits complex workloads that need Kubernetes features. Azure Container Apps runs containers without cluster management, and supports revisions, so traffic can be split between versions. Web App for Containers runs a single container image on App Service. Pipelines use a managed identity or a federated identity to push to the registry, and the host uses a managed identity with the AcrPull role to pull, so no registry password is stored.
GitOps is a related model, in which a controller such as Flux or Argo CD runs in the cluster, and it applies whatever is in a Git repository. A pipeline then changes a manifest in Git, rather than calling the cluster, and the cluster's state is kept reviewable.
The following diagram compares an image pull secret with an attached container registry for AKS.

Container hosts and registries
Binary deployments
A binary deployment ships compiled output, usually as a zip package, to a service such as Azure App Service or Azure Functions.
# Azure Pipelines
- task: AzureWebApp@1
inputs:
azureSubscription: sc-azure-prod
appType: webAppLinux
appName: contoso-web
package: $(Pipeline.Workspace)/web/*.zip
- task: AzureFunctionApp@2
inputs:
azureSubscription: sc-azure-prod
appType: functionAppLinux
appName: contoso-func
package: $(Pipeline.Workspace)/func/*.zip
# GitHub Actions
- uses: azure/webapps-deploy@v3
with:
app-name: contoso-web
package: ./publishRun from package mounts the zip as a read-only file system, instead of extracting files, by setting WEBSITE_RUN_FROM_PACKAGE=1. This gives atomic deployment, faster cold starts and no file-locking conflicts, as the whole package changes at once. The package should be the artifact from the build stage, and it should not be rebuilt in the release.
Binaries for virtual machines are copied through a deployment job that targets VM resources, or by a configuration management tool. For on-premises servers, the agent on the machine performs the installation.
Zip deployments
Script deployments
Scripts cover work that has no dedicated task. The AzureCLI@2 and AzurePowerShell@5 tasks sign in through a service connection, and then run a script. In GitHub Actions, azure/login signs in, and later steps run az commands.
# Azure Pipelines
- task: AzureCLI@2
inputs:
azureSubscription: sc-azure-prod
scriptType: bash
scriptLocation: scriptPath
scriptPath: scripts/configure-app.sh
arguments: production
# GitHub Actions
- uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- run: ./scripts/configure-app.sh productionScript quality matters, since a failing script may leave a system half changed. Scripts should be stored in the repository and reviewed, should fail on error, such as with set -euo pipefail in Bash, and should be idempotent. If a declarative tool can do the task, it is usually a better choice, because idempotence is then built in.
Deployment scripts that are safe to run
Choosing a form
The following table recaps the tasks and when each form is appropriate.
| Form | Typical target | Azure Pipelines | GitHub Actions |
|---|---|---|---|
| Container | AKS, Container Apps, App Service | Docker@2, KubernetesManifest@1 | docker/build-push-action, azure/k8s-deploy |
| Binary | App Service, Azure Functions | AzureWebApp@1, AzureFunctionApp@2 | azure/webapps-deploy, azure/functions-action |
| Script | Anything with a CLI or API | AzureCLI@2, AzurePowerShell@5 | azure/login with run steps |
Deployment tasks and actions
Registry credentials
An AKS cluster pulls images from Azure Container Registry using a Kubernetes image pull secret that contains a registry password, and security wants that password removed. What should you do?
Attach the registry to the cluster, for example with az aks update --attach-acr, which grants the cluster's kubelet identity the AcrPull role. Pods can then pull images with no stored credential. Enabling the registry's admin account would add another shared credential. Moving the password to Key Vault still leaves a password in use.
What is the benefit of run from package for a deployment?
Show answer
The application runs from a read-only zip, so deployment is atomic and avoids file-locking conflicts.
Exam Tips
Remember for the exam
- Host identities need AcrPull to pull images with no password.
- Run from package gives atomic deployments and avoids file locks.
- AzureCLI@2 signs in through a service connection before running a script.
- Scripts should fail on error and be idempotent.
- Deploy the build artifact; do not rebuild during a release.