Azure az cli Docker Hub Web App ressource configuration - azure

I'm trying to setup a script for automate the creation of a new environment for my app, and i need a docker webapp.
The problem is that i need to pull the image from docker hub.
When i create an env from the interface in juste setup it like that :
The problem is that i don't find out how i can configure the "Source de registre" on Docker Hub by the az cli.
For now the command i'm using to create a new web app ressource is this one
az webapp create -g name_of_group -p name_of_plan -n resource-test2 -i https://registry.hub.docker.com/publisher/name_of_image:version -s name_of_image -w my_password
The problem of this command is that it give me this configuration
Which doesn't work because i can't get logged in (probably because it's not configured as a Docker Hub registre).
Do you know how i can specify this configuration in my az cli command ? Thanks

To deploy the images stored in a private registry or the Docker Hub, you can set the environment variables below:
DOCKER_REGISTRY_SERVER_USERNAME - The username for the ACR server.
DOCKER_REGISTRY_SERVER_URL - The full URL to the ACR server. (For example, https://my-server.azurecr.io.)
DOCKER_REGISTRY_SERVER_PASSWORD - The password for the ACR server.
Get more details here. And you can use the CLI command az webapp config appsettings set to do it.

Recently had the same problem deploying azure cloud webapp from a container in my private docker hub repo. UI experience works fine but when I do it using azure cli with 'az webapp create ...' ended up with same problem. I was able to fix it by using 'az webapp config container set ...' command after creating the webapp. See below and in my github repo
# First create the webapp with a docker container:
~$ az webapp create -n $webAppName -g $resGroup -p $servicePlan -i $containerImg -s $dockerUsr -w $dockerPass --tags Lifecycle=Test
# Update docker container settings with your private docker hub repo credentials:
~$ az webapp config container set --name $webAppName --resource-group $resGroup --docker-custom-image-name 'DOCKER|dockeruser/myrepo:tweb1' --docker-registry-server-url 'https://index.docker.io/v1' --docker-registry-server-user 'dockeruser' --docker-registry-server-password 'xxxxxxxxxxx'

Related

How to Deploy local Docker image to Azure app services?

Created Azure app services web app without using any Docker registry integration.
I want achieve below.
1] create, tag image on my Linux machine
2] deploy local Docker image to App services web app using below
az webapp config container set --name springboot-docker-helloworld-app --resource-group SpringBoot --docker-custom-image-name org/dockerspringtboot-metinv:latest
But it is not working.
Is it possible to deploy local Docker images to Azure app services web app ?
You'll need to push your container image to an Azure container registry from which your Azure web app can pull the image.
You can do this using Azure CLI with the following steps:
$ az acr create --resource-group your_rg \
--name yourAcrName --sku Basic
# login to the container registry locally
$ az acr login --name yourAcrName
# update the container registry to use admin-enabled
# https://learn.microsoft.com/en-us/azure/container-registry/container-registry-authentication?tabs=azure-cli#admin-account
$ az acr update -n yourAcrName --admin-enabled true
# tag your local image to the container registry
$ docker tag dockerspringtboot-metinv:latest yourAcrName/dockerspringtboot-metinv:latest
# push image to your container registry
$ docker push yourAcrName/dockerspringtboot-metinv:latest
Then you can create an app service plan and deploy the web app specifying to use your container registry.
$ az appservice plan create -g your-rg \
-n your-app-plan \
--sku B1 --is-linux
# deploy your container as an app in the created App Service plan
$ az webapp create -g your-rg \
-p your-app-plan \
-n dockerspringtboot \
-i yourAcrName/dockerspringtboot-metinv:latest

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.

Docker commands in Azure

Maybe I do not understand the concept of Azure Container Instances (ACI) and Azure at all correctly. I am using Azure CLI on my Windows-Computer and want to create a Windows-container (core-image) with dockerfile. But there is no AZ command available. I am able to create a container, there is no problem. But not with a dockerfile. Is there a possibility to run docker commands for Azure (Azure CLI, Azure bash, Azure powershell)? Maybe somebody can clarify my misunderstanding.
Many thanks in advance, J.
Of curse, yes, you can use the Azure CLI command to build containers with Dockerfile. But there is a queue for the steps.
The docker image is the first step, you can use the CLI command az acr build to build the image directly in the ACR, with your Dockerfile. For example, the Dockerfile is in your local machine and it's windows image:
az acr build -t sample/hello-world:{{.Run.ID}} -r MyRegistry . --platform windows
The ACI is the second step, CLI command az container create will help you to create the container instance with your images. The example command here:
az container create -g MyResourceGroup --name mywinapp --image winappimage:latest --os-type Windows --cpu 2 --memory 3.5
Once you have your image, you should publish it to Azure Container Registry or Docker Hub.
Take a look on the following links, it provides the information to:
Create a container image for deployment to Azure Container Instances
Deploy the container from Azure Container Registry
Deploy your application
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-prepare-app
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-prepare-acr
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-deploy-app
I have recently done the same thing. I have deployed my windows service to Azure Container Instance through Azure Container Registry. Here is step by step process you need to follow. Before performing these steps you need to have published folder of application. You need to install Docker Desktop in your machine.
Create Dockerfile with below commands and put it inside published folder:
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019
COPY . .
ENTRYPOINT Application.exe
Here you need to use base file as per your neeed. You can find Windows base images [here][1]
Now navigate to this directory(published folder path) in Powershell and execute below command:
docker image build -t IMAGE_NAME:TAG . -- name of the image with tag
docker run --rm IMAGE_NAME:TAG -- you can run it locally
Now to push this image to Azure, below are the commands. First login into azure and then azure container registery.
az login -- it will navigate to browser for login
docker login ACR_LOGIN_SERVER_NAME -u ACR_USERNAME --password ACR_PASSWORD
docker tag IMAGE_NAME:TAG ACR_LOGIN_SERVER_NAME/IMAGE_NAME:TAG -- tag local image to azure inside ACR
docker push ACR_LOGIN_SERVER_NAME/IMAGE_NAME:TAG -- push image to ACR
Once you have pushed docker image to ACR, you can see it under Repositories in ACR. Based on this repository, you need to create Azure Container Instance to run your docker image.
To create ACI, click on "Create a resource" and select Containers > Container Instances. Here, you need to key some info like resource group and docker image credentials. Make sure you select Private as Image type and key image registry credentials. This ACI deployment process may take couple of minutes as it will fetch the docker image and then deploy. Once deployment is done, you will see Container running and you can check logs as well.
Hope it helps!!

Deploy image from docker hub to AZure

I want to deploy a image from docker hub to Azure Container Instance.How can we do this.Is it mandatory to push the image first to Azure Container Registry?
All solutions I am getting shows that we need to push the image first to Azure Container Registry.
No, you need not push the image to ACR first, just let the image stay in the docker hub. For example, deploy the Nginx docker image to ACI, the Azure CLI command like below:
az container create -g resourceGroup -n aciName --image nginx --ports 80
As the command shows, you can use the docker image. Actually, the docker hub is the default registry. When you use another registry, you need to add the parameters --registry-login-server, --registry-username and --registry-password. For more details, see az container create.
It also shows clearly in the Azure portal, when you create ACI in the portal, you can see it like below:
You can use docker image directly with the container as follows,
az container create --resource-group myResourceGroup --name mycontainer --image docker image url

Azure ARM - HttpsOnly for webapps

I've tried the following azure command:
az webapp update --resource-group <YourResourceGroupName> --name <YourWebAppName> --set httpsOnly=true
However I got the following response:
az: error: unrecognized arguments: --set httpsOnly=true
I'm running the command in the docker image azuresdk/azure-cli-python version 2.0.23
EDIT:
My mistake: I was not running az update but az deployment (which btw should support the httpsOnly flag IMO).
We should use this command to set HttpsOnly for Azure Web app.
az webapp update --resource-group <YourResourceGroupName> --name <YourWebAppName> --set HttpsOnly=true
I run this command in Azure cloud shell, that works for me:
Also we can check it via Azure portal:
Note:
The Azure CLI version is 2.0.23, we can find the CLI 2.0 release here, we can follow this link to install Azure CLI 2.0.

Resources