4

I'm working on a new container image that runs my worker process to drain an Azure queue. Once the queue is empty my app exits and I'd like the ACI to de-allocate and be removed as well. What I am seeing is the ACI stick around. It is in a "Terminated" state with a restart count of 0 as I would expect (seen in Azure Portal), but why is it not removed/deleted from the ACI list entirely?

I am using the Azure cli to create these instances and am specifying the restart never option. Here is my command line (minus the image specific details):

az container create --cpu 4 --memory 14 --restart-policy never --os-type windows --location eastus

I am of course also wondering where billing stops. Once I see the terminated state I am hoping that billing has stopped. Though this is unclear. I can of course manually delete the ACI and it is gone immediately, should exiting the app do the same?

BrettRobi
  • 3,793
  • 7
  • 40
  • 64

1 Answers1

7

If your container is in terminated state, you are no longer being billed. The resource itself though remains until you delete it though in the event you want to query the logs, events, or details of the container after termination. If you wish to delete existing container groups, writing some code on Azure Functions is a good route so you can define when something should be deleted.

Check out this base example of such a concept.

https://github.com/dgkanatsios/AzureContainerInstancesManagement/tree/master/functions/ACIDelete

jluk
  • 1,000
  • 7
  • 12
  • 4
    Auto-deleting of ACI instances on completion feels like a notable missing feature! – BrettRobi Apr 30 '18 at 16:19
  • 2
    There's a [feedback issue](https://feedback.azure.com/forums/602224-azure-container-instances/suggestions/34066633-support-auto-delete-of-aci-when-container-exits-no) asking for termination on completion – Michael_S_ May 03 '18 at 08:30
  • 3
    Definitely open to feedback, please do vote on this feature! Our initial logic was we'd like to be more conservative on clean-up because we don't want to erase a history of container logs/traces in the event customers want to use them post task completion. – jluk May 10 '18 at 16:10
  • 1
    Understandable, right now we're being conservative until we know for certain we won't remove valuable logs/events you might have wanted. So for now clean-up is on your own, but we'll be revisiting this better clean-up experience once we get some important work like supporting VNETs completed. – jluk Aug 01 '18 at 21:20
  • 1
    I think the middle ground is to provide another parameter to specify if ACI should be deleted automatically after it's terminated. – kimsk May 02 '19 at 15:35