Skip to content

Instantly share code, notes, and snippets.

@ivansharamok
Created September 26, 2017 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivansharamok/7bd14e3c9b733f3c1a607a725d42c433 to your computer and use it in GitHub Desktop.
Save ivansharamok/7bd14e3c9b733f3c1a607a725d42c433 to your computer and use it in GitHub Desktop.
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