Stop an Azure ContainerApp?
Asked Answered
S

3

10

I have an Azure ContainerApp deployed with a single revision, and I'd like to stop it - but not delete it and have to re-deploy it. I see the image in the registry, and there are options via the portal to deploy it to an AppService or ContainerInstance, but not to a ContainerApp.

I also have looked through the az CLI, specifically az containerapp, but see no way to stop a running instance. I can set the scale to 0-1, but it still runs.

Am I missing something? Stopping an instance seems like a pretty normal thing to do...

EDIT - Setting all revisions to inactive doesn't seem to be allowed. See images below.

Revisions

Save Revisions

Spongin answered 16/9, 2022 at 20:53 Comment(0)
M
11

Update: there is now a proper way to stop, see the answer by HQT


You can deactivate a revision to shut down the containers. If you deactivate all active revisions, you will effectively stop your containerapp.

https://learn.microsoft.com/en-us/azure/container-apps/application-lifecycle-management

Once a revision is no longer needed, you can deactivate a revision with the option to reactivate later. During deactivation, containers in the revision are shut down.

When you need it again, you can use activate to get new replicas.

az containerapp revision deactivate --resource-group
                                    --revision
                                    [--name]

az containerapp revision activate --resource-group
                                  --revision
                                  [--name]

If you visit the containerapp url after deactivating all revisions, you will receive an error:

Error 403 - This Container App is stopped.

Momism answered 17/9, 2022 at 9:6 Comment(4)
Deactivating all active revisions doesn't seem to be allowed. See edited question above.Spongin
@Spongin it works using the CLI, I tested it when I posted the answer.Momism
Thanks @Alex-ait, that indeed did work. It'd be helpful if the portal and the CLI were synced. Appreciate the helpSpongin
Using this method, in my case the revision gets reactivated after roughly 3 days. Stopping the container app through the REST API (and Portal/CLI soon) should be the way to go going forward (See @HQT 's answer).Spiderwort
M
5

(july 2023) still can't be done via the portal unfortunately, BUT the ACA dev team just implemented start and stop requests (see this comment), that's neat :

az rest -m POST -u "/subscriptions/$SUBSCRIPTION/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.App/containerapps/$APP_NAME/start?api-version=2023-04-01-preview"
az rest -m POST -u "/subscriptions/$SUBSCRIPTION/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.App/containerapps/$APP_NAME/stop?api-version=2023-04-01-preview"
Matlock answered 28/7, 2023 at 17:56 Comment(0)
R
4

In azure portal if you go to container you have ready to use cli commands under Automation section.

enter image description here

Rog answered 8/1 at 7:10 Comment(1)
This seems to be new sometime in H2 2023 - good to know!Spongin

© 2022 - 2024 — McMap. All rights reserved.