In this article, I'm going to spin up a docker container using Azure Container Instance.
This article follows on from the previous article on getting started with Azure Container Registry
I use the Azure Container Registry created and the docker image I pushed up to it.
I will need the credentials for the Azure Container Registry. To do this, I run this, specifying the ACR name "redfolder":
az acr credential show --name redfolder
I can then get the username and password for the response:
{
"passwords": [
{
"name": "password",
"value": "9MT56hWrpRlFFMF184DXhA/DptdOVkyq"
},
{
"name": "password2",
"value": "3IE0ur6Ijnfwz9BQ/RbKEdekR8/XBtn0"
}
],
"username": "redfolder"
}
So I'm ready to create my container.
I run the following, specifying the all the details I set up in the last article
az container create -g ContainerPlayground -n rfc-the-worlds-best-website --image redfolder.azurecr.io/the-worlds-best-website --cpu 1 --memory 1 --registry-username redfolder --registry-password "9MT56hWrpRlFFMF184DXhA/DptdOVkyq" --dns-name-label rfc-the-worlds-best-website --ports 80
This will create a container instance using the the-worlds-best-website image from the Azure Container Registry redfolder.azurecr.io. This will produce a whole bunch of output:
{
"containers": [
{
"command": null,
"environmentVariables": [],
"image": "redfolder.azurecr.io/the-worlds-best-website",
"instanceView": {
"currentState": {
"detailStatus": "",
"exitCode": null,
"finishTime": null,
"startTime": "2019-01-28T11:24:36+00:00",
"state": "Running"
},
"events": [
{
"count": 1,
"firstTimestamp": "2019-01-28T11:24:27+00:00",
"lastTimestamp": "2019-01-28T11:24:27+00:00",
"message": "pulling image \"redfolder.azurecr.io/the-worlds-best-website\"",
"name": "Pulling",
"type": "Normal"
},
{
"count": 1,
"firstTimestamp": "2019-01-28T11:24:33+00:00",
"lastTimestamp": "2019-01-28T11:24:33+00:00",
"message": "Successfully pulled image \"redfolder.azurecr.io/the-worlds-best-website\"",
"name": "Pulled",
"type": "Normal"
},
{
"count": 1,
"firstTimestamp": "2019-01-28T11:24:36+00:00",
"lastTimestamp": "2019-01-28T11:24:36+00:00",
"message": "Created container",
"name": "Created",
"type": "Normal"
},
{
"count": 1,
"firstTimestamp": "2019-01-28T11:24:36+00:00",
"lastTimestamp": "2019-01-28T11:24:36+00:00",
"message": "Started container",
"name": "Started",
"type": "Normal"
}
],
"previousState": null,
"restartCount": 0
},
"livenessProbe": null,
"name": "rfc-the-worlds-best-website",
"ports": [
{
"port": 80,
"protocol": "TCP"
}
],
"readinessProbe": null,
"resources": {
"limits": null,
"requests": {
"cpu": 1.0,
"memoryInGb": 1.0
}
},
"volumeMounts": null
}
],
"diagnostics": null,
"id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/ContainerPlayground/providers/Microsoft.ContainerInstance/containerGroups/rfc-the-worlds-best-website",
"identity": null,
"imageRegistryCredentials": [
{
"password": null,
"server": "redfolder.azurecr.io",
"username": "redfolder"
}
],
"instanceView": {
"events": [],
"state": "Running"
},
"ipAddress": {
"dnsNameLabel": "rfc-the-worlds-best-website",
"fqdn": "rfc-the-worlds-best-website.northeurope.azurecontainer.io",
"ip": "52.142.82.41",
"ports": [
{
"port": 80,
"protocol": "TCP"
}
],
"type": "Public"
},
"location": "northeurope",
"name": "rfc-the-worlds-best-website",
"networkProfile": null,
"osType": "Linux",
"provisioningState": "Succeeded",
"resourceGroup": "ContainerPlayground",
"restartPolicy": "Always",
"tags": {},
"type": "Microsoft.ContainerInstance/containerGroups",
"volumes": null
}
And that's it.
I test it by navigating to http://rfc-the-worlds-best-website.northeurope.azurecontainer.io
Easy isn't it.
So container instances are great for quickly spinning up a container.
There are limitations however. The two big ones for me are the lack of support for HTTPS and DNS.
There are ways to solve this fairly easily though.
I'm my case, I can simply add to my Cloudflare account via CNAME and let it handle the HTTPS certificate:
Which then allows me to access the container with a meaningful name and over HTTPS:
To clean up the container, run:
az container delete -g ContainerPlayground --name rfc-the-worlds-best-website --yes