Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created September 25, 2019 21:05
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 adamdriscoll/cb868fb1a0c5ba276954a54e7e41fe6d to your computer and use it in GitHub Desktop.
Save adamdriscoll/cb868fb1a0c5ba276954a54e7e41fe6d to your computer and use it in GitHub Desktop.
Deploys a Docker Image to Azure Container Instances
param(
$DockerUserName = "",
$DockerPassword = "",
$ShareUserName = "",
$SharePassword = "",
$ServicePrincipalName = "",
$ServicePrincipalPassword = ""
)
$azurePassword = ConvertTo-SecureString $ServicePrincipalPassword -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($ServicePrincipalName , $azurePassword)
$storagePassword = ConvertTo-SecureString $SharePassword -AsPlainText -Force
$storageCred = New-Object System.Management.Automation.PSCredential($ShareUserName , $storagePassword)
$registryPassword = ConvertTo-SecureString $DockerPassword -AsPlainText -Force
$registryCred = New-Object System.Management.Automation.PSCredential($DockerUserName , $registryPassword)
Connect-AzAccount -ServicePrincipal -Credential $psCred -Force -TenantId myTenant.onmicrosoft.com
Start-Sleep 2
$Module = Import-Module Az -PassThru -ErrorAction SilentlyContinue
if ($null -eq $Module)
{
Install-Module Az -Scope CurrentUser -Force
}
$Container = Get-AzContainerGroup -Name "container-name" -ResourceGroupName 'resource-group' -ErrorAction SilentlyContinue
if ($null -ne $Container)
{
Remove-AzContainerGroup -InputObject $Container
}
$Params = @{
ResourceGroupName = "resource-group"
Name = "container-name"
Cpu = 1
MemoryInGB = 1.5
Port = @(8080, 10001)
DnsNameLabel = "container-name"
OsType = 'Linux'
Image = "adamdriscoll/myImage:1.0.1"
AzureFileVolumeShareName ="my-storage"
AzureFileVolumeAccountCredential = $storageCred
AzureFileVolumeMountPath = "/home/config"
EnvironmentVariable = @{
ENVVAR = "Hello!"
}
RegistryCredential = $registryCred
RegistryServerDomain = "index.docker.io"
}
New-AzContainerGroup @params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment