snippetdockerModerate
On Azure, how do I run a short-lived Docker container on a schedule?
Viewed 0 times
containershortliveddockerazurehowschedulerun
Problem
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:
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.
docker login
docker pull example.com/bar:latest
docker run example.com/bar:latestCan 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.
Solution
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
To create the container, you can use Azure CLI (
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.
(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.
Context
StackExchange DevOps Q#1620, answer score: 15
Revisions (0)
No revisions yet.