Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deploy Azure container from ACR
<#
.Synopsis
Deploy Azure Container Instance from a specified image.
Requires az-cli >= 2.0.13
.Example
.\deploy-aci-from-acr.ps1 -ContainerName myContainer -ResourceGroup myGroup -RegistryName myRegistry -ImageName myregistry.azurecr.io/myImageWithTag -Port 8983
.Example
.\deploy-aci-from-acr.ps1 -ContainerName myContainer -ResourceGroup myGroup -RegistryName myRegistry -ImageName myregistry.azurecr.io/myImageWithTag -Port 8983 -CpuCores 2 -CommandLine 'myscript.sh'
#>
[CmdletBinding()]
param(
[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='create-basic-cores.sh'
)
$Error.Clear()
Trap
{
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
}
break;
}
# 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
}
else{
# 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
You can’t perform that action at this time.