- Courses
- đź’»Programming Languages
- 🪟PowerShell
- Enterprise-Grade PowerShell
- Infrastructure Automation
- Containers
On this page
PowerShell Container Automation: ACI, AKS, ECS & Best Practices
Updated on June 27, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
PowerShell provides a comprehensive automation framework for containerized workloads across Azure and AWS. For Azure, the Az.ContainerInstance module enables serverless container execution via Azure Container Instances (ACI), while Container App Jobs offer scheduled, long-running task execution with managed identity support. Azure Functions with PowerShell triggers provide event-driven automation for container lifecycle management. For AWS, the AWS.Tools.ECS module manages Elastic Container Service tasks and services. Enterprise‑grade container automation requires immutable, versioned images stored in registries such as Azure Container Registry (ACR) or Amazon Elastic Container Registry (ECR), with orchestration through Azure Kubernetes Service (AKS) or Amazon EKS. Security best practices include using managed identities or IAM roles, scanning images for vulnerabilities, and never embedding secrets in container images.
Docker Automation with PowerShell​
Docker remains the foundation of container workflows. PowerShell can orchestrate Docker operations directly, integrating container tasks into scripts and CI/CD pipelines.
Building Images​
The docker build command creates an immutable image from a Dockerfile:
docker build -t webapp:1.0 .
The -t flag tags the image with a name and version. The trailing dot specifies the build context — the current directory containing the Dockerfile and any referenced files. This creates a portable artifact that can run anywhere Docker is installed.
Running Containers​
The docker run command starts a container from an image:
docker run -d -p 8080:80 --name web01 webapp:1.0
The -d flag runs the container in detached mode (background). The -p 8080:80 flag maps host port 8080 to container port 80. The --name flag assigns a name for easier management. PowerShell can wrap these commands in functions to standardise deployments across environments.
Managing Container Lifecycle​
Common management commands include listing, stopping, and removing containers:
docker ps # List running containers
docker stop web01 # Gracefully stop the container
docker rm web01 # Remove the stopped container
The docker ps command shows running containers with their IDs, names, and status. docker stop sends a SIGTERM signal, allowing the container to shut down gracefully. docker rm permanently removes the container, freeing disk space.
Automating Image Tagging and Versioning​
Versioning is essential for traceability and rollback:
$version = "1.0.$(Get-Date -Format yyyyMMddHHmm)"
docker tag webapp:latest "registry.example.com/webapp:$version"
The Get-Date cmdlet generates a timestamp for unique versioning. The docker tag command creates an alias for the image, pointing it to a registry location with the version tag.
Running PowerShell in Containers​
Microsoft provides official PowerShell Docker images:
docker run mcr.microsoft.com/powershell:latest pwsh -c "Get-Date; Write-Host 'Hello from Container!'"
This command pulls the latest PowerShell image from Microsoft Container Registry and executes a simple script. The -c parameter passes a command string to the PowerShell executable. This pattern is useful for testing scripts in isolated environments.
Container Registries​
Registries store and distribute container images. PowerShell automates authentication, tagging, pushing, and pulling images.
Azure Container Registry (ACR)​
ACR is a private registry service integrated with Azure. Authentication can be performed using Azure PowerShell or the Azure CLI.
Authenticate using Azure CLI
Connect-AzAccount
$acr = Get-AzContainerRegistry -ResourceGroupName "ProdRG" -Name "ProdACR"
az acr login --name $acr.Name
Connect-AzAccount authenticates the PowerShell session. Get-AzContainerRegistry retrieves the registry object. The az acr login command authenticates Docker with ACR using Azure credentials.
Push an image to ACR
docker tag webapp:1.0 prodacr.azurecr.io/webapp:1.0
docker push prodacr.azurecr.io/webapp:1.0
First, the image is tagged with the registry's fully qualified name. Then docker push uploads the image to ACR.
ACR Tasks for automated builds
ACR Tasks enable cloud-native image builds directly from source code without a local Docker daemon:
az acr build --registry ProdACR --image webapp:1.0 .
This command builds an image from the current directory's source code and pushes it to ACR in a single step.
Amazon Elastic Container Registry (ECR)​
ECR is AWS's private container registry. Authentication requires a token from AWS.
Authenticate to ECR
(Get-ECRAuthorizationToken).AuthorizationData | ForEach-Object {
docker login -u AWS -p $_.AuthorizationToken $_.ProxyEndpoint
}
Get-ECRAuthorizationToken retrieves a base64-encoded token. The AuthorizationData property contains the token and proxy endpoint. docker login uses these to authenticate with ECR.
Push an image to ECR
docker push <aws_account_id>.dkr.ecr.ap-northeast-1.amazonaws.com/webapp:1.0
The repository URI follows the format: {account_id}.dkr.ecr.{region}.amazonaws.com/{repository}:{tag}.
Azure Container Instances (ACI)​
ACI provides serverless container execution without managing orchestration. It is ideal for batch jobs, short-lived workloads, and event-driven automation.
Creating a Container Group​
The New-AzContainerGroup cmdlet creates a container group — a collection of containers that share the same lifecycle:
New-AzContainerGroup `
-ResourceGroupName "ProdRG" `
-Name "webapp-ci" `
-Image "prodacr.azurecr.io/webapp:1.0" `
-OsType Linux `
-Cpu 1 `
-MemoryInGb 1
The -Image parameter specifies the container image. -OsType must match the image's operating system. -Cpu and -MemoryInGb allocate resources to the container group. ACI supports both Linux and Windows containers.
Starting and Stopping Container Groups​
PowerShell can manage the full lifecycle of container groups:
# Start a container group
Start-AzContainerGroup -ResourceGroupName "ProdRG" -Name "webapp-ci"
# Stop a container group
Stop-AzContainerGroup -ResourceGroupName "ProdRG" -Name "webapp-ci"
# Get container group status
Get-AzContainerGroup -ResourceGroupName "ProdRG" -Name "webapp-ci"
Start-AzContainerGroup resumes a stopped container group. Stop-AzContainerGroup deallocates compute resources, stopping billing for compute (storage costs continue). Get-AzContainerGroup returns properties including containers, image registry credentials, restart policy, IP address type, OS type, state, and volumes.
Removing Container Groups​
Remove-AzContainerGroup -ResourceGroupName "ProdRG" -Name "webapp-ci"
Remove-AzContainerGroup permanently deletes the container group and all associated resources. The operation does not delete user-provided resources such as volumes.
Azure Container Apps Jobs​
Container App Jobs provide scheduled or event-driven execution of containerized tasks. They are ideal for long-running maintenance tasks that are not a good fit for Azure Functions.
Architecture Overview​
A typical Container App Job architecture includes:
- A container image with Azure PowerShell modules installed
- Script files mounted from Azure Files storage
- Managed identity for authentication
Deploying a Container App Job​
# Create Container Apps environment
az containerapp env create `
--name $containerAppsEnvironment `
--resource-group $resourceGroup `
--infrastructure-subnet-resource-id $subnetId `
--logs-workspace-id $workspaceCustomerId `
--logs-workspace-key $workspaceKey `
--enable-workload-profiles `
--location $location
# Create storage account and SMB share
az storage account create `
--name $storageAccountName `
--resource-group $resourceGroup `
--location $location `
--sku Standard_LRS `
--kind StorageV2
az storage share-rm create `
--access-tier Hot `
--enabled-protocols SMB `
--quota 10 `
--name $shareName `
--storage-account $storageAccountName
# Upload script files
az storage file upload `
--source timer1.ps1 `
--share-name $shareName `
--path timer1.ps1 `
--account-name $storageAccountName `
--auth-mode key
The Container Apps environment provides the infrastructure for running container apps. The storage account and SMB share host the PowerShell scripts. The az storage file upload command uploads scripts to the share.
Executing Scripts with Managed Identity​
Behind the scenes, Connect-AzAccount is executed with managed identity, eliminating credential management in maintenance scripts:
Write-Output "This is example job script"
Get-AzResourceGroup | Format-Table
The managed identity is automatically used for authentication, so the script does not need to include credentials or explicit login commands.
Azure Functions with PowerShell​
Azure Functions provide event-driven, serverless compute. PowerShell support enables automation triggered by HTTP requests, timers, queues, or other events.
Creating a PowerShell Function App​
$resourceGroup = "MinecraftTest"
$location = "westeurope"
az group create -n $resourceGroup -l $location
$functionAppName = "MinecraftFuncsTest"
$funcStorageAccountName = "minecraftfuncstest"
az storage account create -n $funcStorageAccountName -l $location -g $resourceGroup --sku Standard_LRS
az functionapp create `
-n $functionAppName `
--storage-account $funcStorageAccountName `
--consumption-plan-location $location `
--runtime powershell `
-g $resourceGroup
The Azure CLI creates the resource group, storage account, and function app. The --runtime powershell parameter configures the function app to use the PowerShell worker.
Triggering Container Operations​
A PowerShell function can start or stop container groups in response to events:
# Function trigger example
param($Timer)
$containerName = $env:ContainerName
$resourceGroup = $env:ResourceGroup
Stop-AzContainerGroup -ResourceGroupName $resourceGroup -Name $containerName
The function retrieves container details from environment variables and executes the stop operation. Azure Functions automatically authenticate using managed identity.
Use Cases​
PowerShell Functions are suitable for:
- Scheduled container shutdown to control costs
- HTTP-triggered container deployment
- Queue-driven batch processing
- Event-driven infrastructure automation
AWS Container Services​
AWS provides multiple container orchestration options with PowerShell support.
Amazon ECS (Elastic Container Service)​
ECS is AWS's container orchestration service. The AWS.Tools.ECS module provides cmdlets for managing tasks and services.
Run an ECS task
Start-ECSTask `
-Cluster "ProdCluster" `
-TaskDefinition "webapp:1"
Start-ECSTask launches a task from the specified task definition. The task definition includes the container image, CPU, memory, and networking configuration.
Create a service
New-ECSService `
-Cluster "ProdCluster" `
-ServiceName "webapp-service" `
-TaskDefinition "webapp:1" `
-DesiredCount 2
New-ECSService creates a long-running service that maintains a desired number of running tasks. ECS automatically handles scaling and recovery.
Invoke commands on containers
Invoke-ECSCommand `
-Cluster "ProdCluster" `
-Task "task-id" `
-Container "webapp" `
-Command "ls -la"
Invoke-ECSCommand runs a command remotely on a container within a task.
Amazon EKS (Elastic Kubernetes Service)​
EKS is AWS's managed Kubernetes service. PowerShell interacts with EKS through kubectl.
Configure kubectl for EKS
aws eks update-kubeconfig --region us-west-2 --name my-cluster
kubectl get nodes
The aws eks update-kubeconfig command updates the local Kubernetes configuration to point to the EKS cluster.
Deploy to EKS
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply deploys Kubernetes resources defined in YAML files. PowerShell can wrap these commands in scripts for CI/CD integration.
Enterprise Container Automation Patterns​
Expert‑level container automation requires more than running individual commands. Workflows must be:
- Immutable — containers are never patched; they are rebuilt from source
- Versioned — every image has a unique, traceable tag
- Registry‑driven — images flow through dev → test → prod
- Orchestrated — AKS, EKS, or ECS handle scaling and scheduling
- Secure — no secrets in images; use vaults and managed identities
- Policy‑compliant — enforce image scanning, signing, and RBAC
Typical Enterprise Pipeline​
- Build image — compile application and create container image
- Scan image — check for vulnerabilities using ACR or ECR scanning
- Tag and push — version the image and push to registry
- Deploy to dev — test in a development environment
- Run tests — validate functionality
- Promote to staging — deploy to staging for further validation
- Deploy to production — via GitOps or CI/CD pipelines
PowerShell acts as the orchestration layer, invoking build tools, registry operations, and deployment commands.
Security Considerations​
- Never store secrets in images — use environment variables or volumes
- Use managed identities (Azure) or IAM roles (AWS) for authentication
- Scan images for vulnerabilities before deployment
- Enforce signed images with Notary or ACR Trust Policy
- Restrict registry access using RBAC or IAM policies
- Apply network policies in Kubernetes to limit pod communication
- Implement least‑privilege permissions for containers
PowerShell scripts must integrate these security controls into automation pipelines.
Summary​
Containers are a core component of modern infrastructure automation. As an expert PowerShell practitioner, you must be able to:
- Build, run, and manage Docker containers
- Automate image tagging, versioning, and distribution
- Work with Azure Container Registry and AWS ECR
- Deploy containers to ACI, AKS, ECS, and EKS
- Use Container App Jobs for scheduled task execution
- Trigger container operations with Azure Functions
- Integrate container workflows into CI/CD pipelines
- Enforce security, identity, and governance standards
Mastering container automation enables consistent, scalable, cloud‑native infrastructure across any environment.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Virtual Machines
Next
Building Tooling and Automation Frameworks
-
Docker Automation with PowerShell
- Building Images
- Running Containers
- Managing Container Lifecycle
- Automating Image Tagging and Versioning
- Running PowerShell in Containers
-
Container Registries
- Azure Container Registry (ACR)
- Amazon Elastic Container Registry (ECR)
-
Azure Container Instances (ACI)
- Creating a Container Group
- Starting and Stopping Container Groups
- Removing Container Groups
-
Azure Container Apps Jobs
- Architecture Overview
- Deploying a Container App Job
- Executing Scripts with Managed Identity
-
Azure Functions with PowerShell
- Creating a PowerShell Function App
- Triggering Container Operations
- Use Cases
-
AWS Container Services
- Amazon ECS (Elastic Container Service)
- Amazon EKS (Elastic Kubernetes Service)
-
Enterprise Container Automation Patterns
- Typical Enterprise Pipeline
- Security Considerations
-
Summary
