Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Deploy Azure container from ACR
Deploy Azure Container Instance from a specified image.
Requires az-cli >= 2.0.13
.\deploy-aci-from-acr.ps1 -ContainerName myContainer -ResourceGroup myGroup -RegistryName myRegistry -ImageName -Port 8983
.\deploy-aci-from-acr.ps1 -ContainerName myContainer -ResourceGroup myGroup -RegistryName myRegistry -ImageName -Port 8983 -CpuCores 2 -CommandLine ''
[Parameter(Mandatory=$true)] $ContainerName,
[Parameter(Mandatory=$true)] $ResourceGroup,
[Parameter(Mandatory=$true)] $RegistryName,
[Parameter(Mandatory=$true)] $ImageName,
[Parameter(Mandatory=$false)] $Port=8983,
[Parameter(Mandatory=$false)] $CpuCores=1,
[Parameter(Mandatory=$false)] $MemoryInGb=1,
[Parameter(Mandatory=$false)] $CommandLine=''
Write-Error $_.ErrorDetails.Message
Write-Error $_.InvocationInfo.PositionMessage
Write-Error $_.CategoryInfo.ToString()
Write-Error $_.FullyQualifiedErrorId
$e = $_.Exception
while ($e.InnerException) {
$e = $e.InnerException
$msg += "`n" + $e.Message
# login to ACR
# if can't locing into ACR, try restarting or even re-installing Docker engine.
az acr login -n $RegistryName
# get registry password
$acrPassword = az acr credential show -n $RegistryName --query "passwords[0].value"
if ($CommandLine){
# create a ACI from ACR image and execute supplied script
az container create -g $ResourceGroup -n $ContainerName --image $ImageName --cpu $CpuCores --memory $MemoryInGb --registry-password $acrPassword --ip-address public --port $Port --command-line $CommandLine
# create a ACI from ACR image
az container create -g $ResourceGroup -n $ContainerName --image $ImageName --cpu $CpuCores --memory $MemoryInGb --registry-password $acrPassword --ip-address public --port $Port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment