20

I have a fairly simple Unix shell script packaged up in an Alpine Linux Docker container hosted on an Azure container registry. A VM runs this script with cron:

docker login <snip>
docker pull example.com/bar:latest
docker run  example.com/bar:latest

Can I do without the VM and use Azure services instead, perhaps with some sort of scheduler running this on an Azure Container Instance?

My motivation is not wanting to maintain and pay for the VM.

Sijmen Mulder
  • 303
  • 1
  • 2
  • 5

6 Answers6

15

Azure Container Instances (ACI) may be a good option as you suggest. These let you run a container directly on Azure, without having to manage a VM, with per-second billing for the time the container is used.

Although one of the demos on that blog mentions Kubernetes, the idea of ACI is that you can create a container through the Azure CLI with az container create, just like on your local workstation with docker create.

To create the container, you can use Azure CLI (az command, see quick start docs) or Azure Cloud Shell.

You would need to create/run the container on a schedule from somewhere else - Azure Functions might be a good place to run the "container create" command from a scheduled function. This supports bash, PowerShell, and other languages - all running on Windows.

If you want to keep using Docker containers without running VMs or learning Kubernetes, this might be a good option.

Alternatively, you could move all your code into Azure Functions, but that's a bigger decision.

Update: Jan 2019 - Azure Logic Apps can be used to run scheduled tasks as well. This replaced Azure Scheduler in Jan 2022.

RichVel
  • 902
  • 6
  • 16
5

For an alternative approach, I would investigate Azure functions:

No VM continually running.

2

A scheduled devops pipeline is an easy and free way to run azure cli tasks on a recurring basis.

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml

Nathan
  • 156
  • 4
1

For short-lived containers, you could use ACA (Azure Container Apps) if you don't want to use AKS or Kubernetes. Then in ACA you can have auto scale rules setup for your container app and scale minimum instances down to 0 and have an ACA trigger that runs (for example) when there is a new service bus message or event hub message.

A Note about Azure Functions:

According to Microsoft Well Architected Framework's Mission Critical Guidelines (and I agree), Azure Functions are not recommended for mission critical workflows. For mission critical workflows that do have some non-critical flows, Azure Functions maybe ok. But you will have make that decision. There are other cons to using Functions over containers Here is the Critical Guidelines document:

https://learn.microsoft.com/en-us/azure/well-architected/mission-critical/mission-critical-application-platform

"...Mission-critical workloads have critical and non-critical system flows. Azure Functions is a viable choice for flows that don't have the same stringent business requirements as critical system flows. It's well suited for event-driven flows that have short-lived processes because functions perform distinct operations that run as fast as possible."

ReidK
  • 11
  • 2
0

I haven't done this myself, but I wonder if an Azure Container Registry (ACR) task could be used to trigger a container on a schedule?

This ACR tutorial seems to suggest that you can schedule a container run as follows:

az acr task create --name timertask --registry $ACR_NAME --cmd mcr.microsoft.com/hello-world --schedule "0 21 * * *" --context /dev/null
daviewales
  • 101
  • 2
0

It looks like Jobs in Azure Container Apps is likely the current best solution for this. learn.microsoft.com/en-us/azure/container-apps/jobs

CLo
  • 101
  • 1