In this post, we will go over how to deploy an Azure container instance based on a Docker image in a private Docker Hub repository. While Azure provides it’s Container Repository, you may already be storing your images in Docker Hub under a private repository there. I recently was trying to deploy Universal Dashboard as a container and had to deal with this type of configuration and found it a bit difficult to find the information I needed to easily deploy from the remote repository. Hopefully, this helps save you some time.

The first step is to set up your Docker Hub repository and push the image you would like to deploy.

Next, you’ll need an Azure Service Principal to use for authenticating with Azure in your deployment script. To create a service principal, you can use the New-AzADServicePrincipal cmdlet. Follow this guide to set up the service principal.

Make sure to assign the service principal to the correct subscription with Contributor permissions. This document shows you how to do that. If you do not set this permission, your service principal will not be assigned to any subscriptions and you will receive cryptic errors about subscription ID being null when you try and execute commands; even though you are connecting successfully.

If you want persistent storage for your container, you should create a Storage Account and file share in Azure via the portal or the PowerShell module. The username for your storage account is the storage account name and the password is the storage key on the Access Keys tab of the account.

Azure Storage Access Keys

Once this is ready, you can use the following script to deploy your private image to Azure Container Instances.

What you need to make sure that you do is that you set the RegistryServerDomain to index.docker.io and that when you specify your image name you make sure to include your username, the repository name, and the tag name. The storage account username is application ID and the password is the secret that you can generate from the portal or the one you retrieved when you created the account with PowerShell.