How to Deploy local Docker image to Azure app services? - azure

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

Related

Deploy docker compose on Azure Container App

from ACA docs we have to specify target port of the container
az containerapp create \
--name my-container-app \
--resource-group $RESOURCE_GROUP \
--environment $CONTAINERAPPS_ENVIRONMENT \
--image mcr.microsoft.com/azuredocs/containerapps-helloworld:latest \
--target-port 80 \
--ingress 'external' \
--query configuration.ingress.fqdn
Now my question is how to deploy via docker-compose not just a single image, since there is a single target-port?
If you want to deploy multiple containers to a single container app, you can define more than one container in the configuration's containers array
Reference: Containers in Azure Container Apps Preview | Microsoft Docs
Alternative
If you want to deploy your application via Docker Compose, you can deploy to Azure Web app
While creating the web app, select publish as Docker Container. Under Docker, select options as Docker Compose and provide the Docker Compose file

Azure az cli Docker Hub Web App ressource configuration

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'

How can I import a container to ACR and configure it to be a linux platform container?

When building my docker image locally and import it to Azure Container Registry (ACR), the Image platform is Windows. It should be Linux. How can I import my image as a Linux platform?
I am using this command to import the image to my ACR.
az acr import
By using the command az acr import means that you can import an image to an Azure Container Registry from another Container Registry. So you should have container images from a public registry or another Azure container registry, in the same or a different Azure subscription or tenant or from a non-Azure private container registry. Read Import container images to a container registry for more details.
In this case, if you have built the images locally, you can push the images directly to the ACR instead of using import. You can make it as the Tutorial: Create an Azure container registry and push a container image:
log in to your Azure Container Registry instance
az acr login --name <acrName>
tag the image with the full name of the registry's login server.
docker tag <localImage> <acrLoginServer>/<acrRepository>:<tag>
Push image to Azure Container Registry
docker push <acrLoginServer>/<acrRepository>:<tag>
Use the following command to import from another ACR from a different subscription.
az acr import --name <DESTINATION-ACR> --force\
--source <SOURCE-ACR-NAME>/IMAGE-NAME:IMAGE-TAG \
--image IMAGE-NAME:IMAGE-TAG \
--username <USERNAME> \
--password <PASSWORD>

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.

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

Resources