Menu Home

Schedule Start/Stop of Azure Container Instances

I really like Azure Container Instances (ACI), it is the simplest way to run containers in Azure. However I find it pretty strange that it don’t have built-in scheduled start/stop of the container groups, especially considering that ACI is not really cost effective if you run the containers 24×7. If you need your containers running 24×7 then you are better off using Azure Web Apps or Kubernetes. In the past I have used build containers in Azure Container Registry as they can be scheduled, but they are even more expensive to run that using ACI so not that is not really recommended.

Well enough ranting, lets see how we can fix it ourselves. Obviously we can write some code that we can execute, e.g. from an Azure function that starts or stops our container at specific intervals by invoking the ARM API. But that is a bit too much work, it would preferable to have a no code solution, like Logic App schedule when our container should start and stop.

If you look inside Logic App for ACI actions you were until recently not in much luck as there was only a few ACI specific actions, none of which could start or stop a container group. Luckily those have been added now, together with a few other useful actions for ACI.

Before these actions where added you could use the Azure Resource Manager action Invoke Resource Operation. That is a pretty useful action as it will allow you to call any ARM rest API, that might not otherwise have native Logic App actions.

As an example I can show you how I used it to schedule start and stop of my Minecraft server, that I have blogged about before.

My Logic App for starting the server looks like this

As you can see it is setup with a Recurrence trigger, which ensures that the server is started everyday at 14.00. I have another Logic App setup in a similar way which turns off the server at 21.00.

When the triggers fire, they run the Invoke Resource operation action, which basically calls the ARM API for starting or stopping the container https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/start.

The magic here is to know that this action exists, then you just need to find the ARM REST API that you are interested in using and check the documentation, for which api-version to use.

Categories: Software

Tagged as:

Simon J.K. Pedersen

5 replies

  1. Thanks for the article, it certainly helped point me in the right direction. In our case we had a container that we wanted to start periodically to go talk to a remote API and download some data to SQL server. So all we needed to do was start the container and it terminated whenever the container had finished doing its thing.

  2. I drop a comment whenever I like a article on a website or I hhave something to add to the conversation. It’s a result of the passion communicateed in thhe post I browsed.
    And on this post Schedule Start/Stop of Azure Container Instances – Simon J.K.
    Pedersen's Azure & Docker blog. I was excited enough to post a
    commebt :-)I actually do have 2 questions forr you if you usually do not mind.
    Could it be only me or dopes it look liike some of
    thhese remarks look like written by brain dead people?
    😛 And, if you are posting on other social sites, I’dlike to follow
    you. Could you make a list every one of all your shared sites like
    your Facebook page, twitter feed, or linkedin profile? https://beechpajama09.bravejournal.net/post/2022/10/09/Gold-Investment-Guidance-Do-Your-Homework

Leave a Reply

Your email address will not be published.