Is it possible to convert the publish method of an App Service from Code to Docker?
Asked Answered
M

4

10

I have set up an Azure App Service (Linux) publish method being Code and have set up the appropriate pipeline to build and deploy my code (nodejs). Now I need more control on the host running my code (need poppler). On dev + test I have created new App Services and have chosen Docker Container as publish method

My question: for my PROD instance, is it possible to change the publish method of my existing App Service or do I have to create a new App Service ?

Assuming the latter, I would need to update the client to point to the new App Service URL. To avoid that, could I first delete the existing App Service and create a new one with the same name ? This would make me lose all stats and logs.

Any alternative suggestions?

enter image description here

Meimeibers answered 15/7, 2020 at 21:57 Comment(0)
L
4

I turned my code-based app into a container by looking at some commands from this guide; https://learn.microsoft.com/en-us/azure/app-service/tutorial-custom-container?pivots=container-linux

The important steps:

  1. Login and select subscription etc

  2. Enable Identity and assign AcrPull role so the App Service can fetch the image

  3. This command:

    az webapp config container set --name <app-name> --resource-group <resource-group> --docker-custom-image-name <registry-name>.azurecr.io/appsvc-tutorial-custom-image:latest --docker-registry-server-url https://<registry-name>.azurecr.io

  4. Now the webapp "Deployment Center" shows Single Container with credentials, registry and Webhook URL setup

Laraelaraine answered 1/10, 2022 at 20:41 Comment(1)
Marking this answer as correct, according to MickeyJones' answer. Disclaimer: I have not tested the solution by myself.Meimeibers
J
2

the App Service Plan can run either code or container

https://learn.microsoft.com/en-us/cli/azure/appservice/plan?view=azure-cli-latest#az-appservice-plan-create

The Web App that target the App Service Plan can come from a custom docker OR a known source code base. (e.g. nodejs)

https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az-webapp-create

when selecting code, you are setting the runtimes and allowing the web app to fetch the code, what happens is the the runtime will used a well known base container and bring in your code.

In the end, you shouldn't have a problem deploying a container based web app on the same App Service Plan even though the original deployment was using Code Base.

you should rely on the Azure CLI more since the portal sometimes doesn't provide you with the full power.

Also hav a look at the App Service Swapping method, to move your traffic from your code base to your container base.

https://learn.microsoft.com/en-us/azure/app-service/deploy-staging-slots

you can leverage slots to help you out with the swapping!

Jamikajamil answered 16/7, 2020 at 2:21 Comment(2)
I have not found any clue in az webapp update that would allow to change/update from code deployment to container deployment. This option is only available at creation time (az webapp create). I have successfully deleted and re-created my webapp with the same name but with a different deployment method in the portal.Meimeibers
I don't think you can update from code to container, my point is more that the Ap Service Plan that you have supports both. so you can have two instances of your code, one using code and one using container within the same service app.Jamikajamil
D
2

Please mark the answer of Jonas Stensved as correct answer, it worked totally fine for me. Only one small edit to his suggestion from my side:

az webapp config container set --name myAppService --resource-group myResourceGroup --docker-custom-image-name myContainerRegistry.azurecr.io/appsvc-tutorial-custom-image:latest --docker-registry-server-url https://myContainerRegistry.azurecr.io
Defazio answered 21/10, 2022 at 14:19 Comment(1)
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From ReviewNador
B
0

This should do the trick:

az webapp config set -g MyResourceGroup -n MyApp \
  --linux-fx-version="DOCKER|mcr.microsoft.com/appsvc/php:8.1-fpm_20220512.1"

Where "mcr.microsoft.com/appsvc/php:8.1-fpm_20220512.1" is dsn of your image.

Using a private container registry? See the az webapp config container set command to configure the credentials.

Bornholm answered 12/5, 2022 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.