<p>For an alternative approach, I would investigate Azure functions:</p>

<ul>
<li><a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview" rel="noreferrer">https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview</a></li>
<li><a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function" rel="noreferrer">https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function</a></li>
</ul>

<p>No VM continually running.</p>

CC BY-SA 3.0
2017-07-28T17:02:45.310Z
2017-07-28T17:02:45.310Z
Mark O'Connor
<p>A scheduled devops pipeline is an easy and free  way to run azure cli tasks on a recurring basis.</p>

<p><a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&amp;tabs=yaml" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&amp;tabs=yaml</a></p>

CC BY-SA 4.0
2021-02-18T00:23:56.310Z
ADO pipelines are for deploying source code -- like when you create a new ADO pipeline it wants to know what branch to deploy and where... can you really unmarry it from all that and just use it to execute arbitrary bash commands on a schedule for free? -- I didn't see anything in that article that indicated this was the case.
BrainSlugs83
CC BY-SA 4.0
2021-02-19T20:42:45.587Z
Yes, just add a [script task](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/bash?view=azure-devops) to your pipeline.  (you can use an inline script and use an empty repo, or you can add a script file to your which the script task points to)
Nathan
CC BY-SA 4.0
2021-02-19T20:47:35.710Z
(You can even reference your container as part of the pipeline definition and run it that way if needed) - [See here](https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#container-resource)
Nathan
CC BY-SA 4.0
2020-04-08T23:30:36.120Z
2020-04-08T23:30:36.120Z
Nathan
<p>For short-lived containers, you could use ACA <strong>(<a href="https://learn.microsoft.com/en-us/azure/container-apps/overview" rel="nofollow noreferrer">Azure Container Apps</a>)</strong> 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.</p>
<p><strong>A Note about Azure Functions:</strong></p>
<p>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:</p>
<p><a href="https://learn.microsoft.com/en-us/azure/well-architected/mission-critical/mission-critical-application-platform" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/well-architected/mission-critical/mission-critical-application-platform</a></p>
<p>&quot;...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.&quot;</p>

CC BY-SA 4.0
2024-04-24T22:31:25.653Z
2024-04-24T22:31:25.653Z
ReidK
<p>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</p>

CC BY-SA 4.0
2024-12-25T02:16:31.393Z
2024-12-25T02:16:31.393Z
CLo
<p>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?</p>
<p>This <a href="https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tasks-scheduled" rel="nofollow noreferrer">ACR tutorial</a> seems to suggest that you can schedule a container run as follows:</p>
<pre class="lang-sh prettyprint-override"><code>az acr task create --name timertask --registry $ACR_NAME --cmd mcr.microsoft.com/hello-world --schedule &quot;0 21 * * *&quot; --context /dev/null
</code></pre>

CC BY-SA 4.0
2024-03-21T05:05:40.930Z
2024-03-21T05:05:40.930Z
daviewales
<p><a href="https://azure.microsoft.com/en-us/blog/announcing-azure-container-instances/" rel="nofollow noreferrer">Azure Container Instances</a>
(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.</p>
<p>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 <code>az container create</code>, just like on your local workstation with <code>docker create</code>.</p>
<p>To create the container, you can use Azure CLI (<code>az</code> command, see <a href="https://docs.microsoft.com/en-us/azure/container-instances/container-instances-quickstart" rel="nofollow noreferrer">quick start docs</a>) or Azure Cloud Shell.</p>
<p>You would need to create/run the container on a schedule from somewhere else - Azure Functions might be a good place to run the &quot;container create&quot; command from  a <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function" rel="nofollow noreferrer">scheduled function</a>.  This supports <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview" rel="nofollow noreferrer">bash, PowerShell, and other languages</a> - all running on Windows.</p>
<p>If you want to keep using Docker containers without running VMs or learning Kubernetes, this might be a good option.</p>
<p>Alternatively, you could move all your code into Azure Functions, but that's a bigger decision.</p>
<p><strong>Update:</strong> Jan 2019 - Azure Logic Apps <a href="https://docs.microsoft.com/en-us/azure/scheduler/migrate-from-scheduler-to-logic-apps" rel="nofollow noreferrer">can be used to run scheduled tasks</a> as well.  This replaced Azure Scheduler in Jan 2022.</p>

CC BY-SA 3.0
2017-07-30T12:12:20.600Z
I wasn't aware I could use PowerShell or Bash for Azure Functions! Thanks
Sijmen Mulder
CC BY-SA 3.0
2017-07-31T05:51:52.180Z
Yes, you can run any executable from Azure Functions, and bash is explicitly mentioned in [this overview doc](https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview).  To call PowerShell modules, see [this blog](https://blogs.msdn.microsoft.com/powershell/2017/02/24/using-powershell-modules-in-azure-functions/).
RichVel
CC BY-SA 4.0
2020-02-01T08:26:05.177Z
It's not the case that all FaaS (serverless) services support bash.  In fact, AWS Lambda only supports bash via custom Layers, a feature added in late 2018 - you can use [this open source layer](https://www.reddit.com/r/aws/comments/a4o7ai/run_bash_in_aws_lambda_via_layers/) to simplify running bash.  Generally, serverless/FaaS services support specific languages, with some providers enabling ways to extend this - for example, AWS has Layers, and Google has a FaaS service that allows any Docker container to run.
RichVel
CC BY-SA 4.0
2020-02-01T08:33:01.043Z
For simplicity if you don't want to use Layers -  you can write a Node/Python Lambda that runs bash, without using Layers - see [lambdash](https://github.com/alestic/lambdash) for one example.
RichVel
CC BY-SA 4.0
2019-01-04T06:55:42.387Z
It’s common to use cloud functions such as Azure Functions, AWS Lambda etc to run installation scripts that configure cloud services (e.g, setup a new cloud environment). So you can expect all serverless services and frameworks to support running bash or similar. Traditionally the first VM you would setup was a “control host” server to use as the place to run all setup of all environments. Going Serverless to run all such scripts means no host to pay for. A control server if hacked leaks a map of your environments, old scripts and possibly cached passwords. Serverless bash is more secure.
simbo1905
CC BY-SA 4.0
2017-07-29T06:50:19.047Z
2022-08-08T06:46:01.363Z
2022-08-08T06:46:01.363Z
RichVel
<p>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:</p>

<pre><code>docker login &lt;snip&gt;
docker pull example.com/bar:latest
docker run  example.com/bar:latest
</code></pre>

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

<p>My motivation is not wanting to maintain and pay for the VM.</p>

CC BY-SA 4.0
2024-11-25T17:56:06.587Z
It looks like Jobs in Azure Container Apps is likely the current best solution for this. https://learn.microsoft.com/en-us/azure/container-apps/jobs
CLo
CC BY-SA 4.0
2024-12-06T17:20:16.967Z
@CLo that looks great, can you add it as an answer (rather than a comment)?
Sijmen Mulder
<docker><containers><azure>
On Azure, how do I run a short-lived Docker container on a schedule?
Sijmen Mulder
# On Azure, how do I run a short-lived Docker container on a schedule?

(Asked by: username_0 on 2017-07-28)

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 
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.

**Tags:** docker, containers, azure

> **Comments:**
> **username_1**: It looks like Jobs in Azure Container Apps is likely the current best solution for this. https://learn.microsoft.com/en-us/azure/container-apps/jobs  
> **username_0**: @username_1 that looks great, can you add it as an answer (rather than a comment)?  

---

## 6 answers

### Answer by username_7 on 2017-07-29. Score: 15 | Accepted answer

[Azure Container Instances](https://azure.microsoft.com/en-us/blog/announcing-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](https://docs.microsoft.com/en-us/azure/container-instances/container-instances-quickstart)) 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](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function). This supports [bash, PowerShell, and other languages](https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview) - 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](https://docs.microsoft.com/en-us/azure/scheduler/migrate-from-scheduler-to-logic-apps) as well. This replaced Azure Scheduler in Jan 2022.

> **Comments:**
> **username_0**: I wasn't aware I could use PowerShell or Bash for Azure Functions! Thanks  
> **username_7**: Yes, you can run any executable from Azure Functions, and bash is explicitly mentioned in [this overview doc](https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview).  To call PowerShell modules, see [this blog](https://blogs.msdn.microsoft.com/powershell/2017/02/24/using-powershell-modules-in-azure-functions/).  
> **username_8**: It’s common to use cloud functions such as Azure Functions, AWS Lambda etc to run installation scripts that configure cloud services (e.g, setup a new cloud environment). So you can expect all serverless services and frameworks to support running bash or similar. Traditionally the first VM you would setup was a “control host” server to use as the place to run all setup of all environments. Going Serverless to run all such scripts means no host to pay for. A control server if hacked leaks a map of your environments, old scripts and possibly cached passwords. Serverless bash is more secure.  
> **username_7**: It's not the case that all FaaS (serverless) services support bash.  In fact, AWS Lambda only supports bash via custom Layers, a feature added in late 2018 - you can use [this open source layer](https://www.reddit.com/r/aws/comments/a4o7ai/run_bash_in_aws_lambda_via_layers/) to simplify running bash.  Generally, serverless/FaaS services support specific languages, with some providers enabling ways to extend this - for example, AWS has Layers, and Google has a FaaS service that allows any Docker container to run.  
> **username_7**: For simplicity if you don't want to use Layers -  you can write a Node/Python Lambda that runs bash, without using Layers - see [lambdash](https://github.com/alestic/lambdash) for one example.  

---

### Answer by username_2 on 2017-07-28. Score: 5

For an alternative approach, I would investigate Azure functions:

* <https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview>
* <https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function>

No VM continually running.


---

### Answer by username_3 on 2020-04-08. Score: 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>

> **Comments:**
> **username_4**: ADO pipelines are for deploying source code -- like when you create a new ADO pipeline it wants to know what branch to deploy and where... can you really unmarry it from all that and just use it to execute arbitrary bash commands on a schedule for free? -- I didn't see anything in that article that indicated this was the case.  
> **username_3**: Yes, just add a [script task](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/bash?view=azure-devops) to your pipeline.  (you can use an inline script and use an empty repo, or you can add a script file to your which the script task points to)  
> **username_3**: (You can even reference your container as part of the pipeline definition and run it that way if needed) - [See here](https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#container-resource)  

---

### Answer by username_5 on 2024-04-24. Score: 1

For short-lived containers, you could use ACA **([Azure Container Apps](https://learn.microsoft.com/en-us/azure/container-apps/overview))** 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."


---

### Answer by username_1 on 2024-12-25. Score: 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


---

### Answer by username_6 on 2024-03-21. Score: 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


---

