Switch docker image in Azure appservice - azure

going through tutorial https://learn.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image
Is it possible to switch docker image on already running appservice?

using this command:
az webapp config container set --name <app-name> --resource-group myResourceGroup --docker-custom-image-name <azure-container-registry-name>.azurecr.io/mydockerimage:v1.0.0 --docker-registry-server-url https://<azure-container-registry-name>.azurecr.io --docker-registry-server-user <registry-username> --docker-registry-server-password <password>
az webapp config container

You should go on deployment center.

Related

Azure Kubernetes cannot pull a image from ACR container

I could use some help with Azure AKS and ACR Integration.
I create a ACR container and attach this container to the AKS cluster. I enable managed identity when creating AKS and I was hoping that ACR also uses managed identity
Here is the script I am using..
az group create --name $RESOURCEGROUP --location eastus
az acr create -n $REGISTRYNAME -g $RESOURCEGROUP --sku Basic
az aks create -n $CLUSTERNAME -g $RESOURCEGROUP --node-count $NODECOUNT --enable-addons monitoring --generate-ssh-keys --enable-managed-identity --attach-acr $REGISTRYNAME
az aks get-credentials -g $RESOURCEGROUP -n $CLUSTERNAME
On AKS, when I get pods, I have a Image Pull error
I see that AKS is using managed identity and ACR is using a Principal ID. How do I fix this issue
Getting the simillar issue once i tried with same cmdlet which you given.
you need to try setting imagePullPolicy to Never and it just worked.
As kubectl describe pod mypd, Kubectl was trying to pull the image, and of course this image doesn't exis on remote server, hence the failure.
Above property will avoid connecting to registry and will use image from docker local images cache.
For Working with ACR & AKS
Import an image into your ACR
Import an image from docker hub into your ACR by running the following:
az acr import -n <acr-name> --source docker.io/library/nginx:latest --image nginx:v1
Would suggest to you follow this Microsoft document Deploy the sample image from ACR to AKS
spec:
containers:
- name: nginx
image: <acr-name>.azurecr.io/nginx:v1
imagePullPolicy: Never
ports:
- containerPort: 80
Refernce : Why am I getting an ErrImagePull error in this Kubernetes deployment?
The ErrImageNeverPull error suggests that your pod spec lists imagePullPolicy: Never, meaning that the kubelet will only look in the node's own cache and not try to pull from ACR. If you remove that, it should work.

How to log into container in Azure?

I deploy a docker image inside Azure Container Instance. The application itself will write some log into the file. Is there some way I can log into the container to view these logs?
az container exec --resource-group <group-name> --name <container-group-name> --exec-command "<command>"
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-exec
You could also create a context with docker and then use docker commands.
docker context create aci myacicontext
docker context use myacicontext
docker logs <CONTAINER_ID>
docker exec -t <CONTAINER_ID> COMMAND
https://docs.docker.com/cloud/aci-integration/#create-an-aci-context
Have found the answer.
az container logs --name your-container-name --resource-group your-resource-group-name
or
az container exec --name your-container-name --resource-group your-resource-group-name --exec-command "cat /home/yourname/xxx.log"

Best way to deploy code and restore database in a managed Application on Azure MarketPlace

Our goal is publishing our offer to Azure MarketPlace. We created an ARM template for our infrastructure and had no issues with that.
Our main issue is how to deploy our code and DB schema through the purchase process.
Microsoft recommends Deployment Scripts so we made ours which contains, CLI commands to restore a .BACPAC sql file, app settings configurations and a CURL command for zip deployment via KUDU for the web application.
.BACPAC and zip package for code are in blob storage.
If we run our scripts in a custom ARM template deployment in Azure, they work fine !!
But when we run them through the marketplace purchase, they fail with no error logs.
Down below you can find our script commands.
"scriptContent": "
az sql db import -s $sqlserver -n $sqldatabase -g $rg -p $sqlpassword -u $sqlusername --storage-key $sqlstoragekey --storage-key-type $storagekeytype --storage-uri $storageuri \r\n
az webapp deployment user set --user-name $deploymentUser --password $deploymentPass \r\n
az webapp config connection-string set --name $applicationName --resource-group $rg --settings DefaultConnection=\"Server=tcp:$sqlserver.database.windows.net,1433;Initial Catalog=$sqldatabase;Persist Security Info=False;User ID=$sqlusername;Password=$sqlpassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;\" --connection-string-type SQLAzure \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings PortalUrl=\https://$applicationName.azurewebsites.net/\ \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings AzureAd:Domain=\"$AADDomain\" \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings AzureAd:ClientId=\"$AADClientId\" \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings AzureAd:TenantId=\"$AADTenantId\" \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings AzureAd:ClientSecret=\"$AADClientSecret\" \r\n
az webapp restart --name $applicationName --resource-group $rg \r\n
curl -X PUT -u $deploymentUser:$deploymentPass https://$applicationName.scm.azurewebsites.net/api/zipdeploy -H \"Content-Type: application/json\" -d \"{'packageUri':'$applicationUri$applicationStorageKey'}\" \r\n
",
In case our approach is wrong, any example, documentation and suggestions will be super helpful.
Feel free to ask for more information if any.
Thank you

How to activate settings in the web app when deployed as deployment-container-image-name

I have deployed a "Container Image" on to Web App Service with the following command.
az webapp create --name Dev-App --plan Dev-AppServicePlan \
--resource-group Dev \
--deployment-container-image-name ...devcontainerregistry.azurecr.io/app-node:latest
After the app was successfully deploment I need to change some Environment variables via the following commands.
az webapp config appsettings set --name Dev-App --resource-group Dev \
--settings MONGO_DSN='mongodb://cosmosdb...'
az webapp config appsettings set --name Dev-App --resource-group Dev \
--settings REDIS_URI='...dev.redis.cache.windows.net:6380...'
az webapp log config --name Dev-App --resource-group Dev \
--docker-container-logging filesystem
Now I have updated and restarted the Web App but it looks like the Image is not redeployed or at least the Environment variables are not there.
az webapp update --name Dev-App --resource-group Dev
az webapp restart --name Dev-App --resource-group Dev
I looked with log tail to the logs but the logs are also not changed. What I mean with "not changed" is that the log output is stucked to the Timestamp "2021-01-13T13:21:31.100Z" even when I restart the Web App.
az webapp log tail --name Dev-App --resource-group Dev
In this Articles from MS is described that a restart should be enough but then should also the log output should be changed.
2: Redeploy a container to Azure App Service after making changes
Configure a custom container for Azure App Service
Any hint how to activate the new settings in the custom image setup or trigger a redeployment?
FYI: I have also created a question in the azure community.
https://learn.microsoft.com/en-us/answers/questions/230584/how-to-activate-settings-in-the-web-app-when-deplo.html
It seems you want to updates the environment variables just like add them in the command:
docker run --name container_name image -e env_var1 -e env_var2
The Azure CLI command just sets the environment variables for the Web App service, you can see them in the Kudu, but it's not the same result as the docker run command.
I recommend you use the docker-compose to deploy your image to the Web App service. Here is the example for the docker-compose. You can update the environment variables in the environment option of the docker-compose file in the portal. Then it will restart again and refresh the logs. And the variables you added will also take effect.
Well the solution for my problem was that I change the registry from "Private Registry" to "Azure Container Registry" in the "container settings" page after running the following command
az webapp create --name Dev-App \
--plan Dev-AppServicePlan \
--resource-group chat-Dev \
--deployment-container-image-name devcontainerregistry.azurecr.io/chat-node:latest
I have put the acr data into the fields and activated the "Continous Deployment"
After this change every settings change triggers a restart and the ENV Variables was in the new instance.

How do I stop an Azure Container Instance?

I'm still new to the Azure Container Instance scene. I have managed to complete the container instance tutorial. However, I've noticed that the tutorial does not show the reader how to stop a running container instance. The nearest command that gaurantees the container instance is indeed stopped / terminated, is by deleting the Resource Group which created the container.
az group delete -n <ResourceGroupNameThatCreatedContainerInstance>
Is this the correct approach?
The Azure CLI updated and now its possible.
Stop
az container stop --name
--resource-group
[--subscription]
Restart
az container restart --name
--resource-group
[--subscription]
You can use az container delete
az container delete -g MyResourceGroup --name mynginx

Resources