1

While learning Azure I have decided to move my personal website from some other VPS provider to Azure. I have chosen Azure Container Apps as it is serverless solution with some free resources per month. Because traffic on my website is not high it should be fine for me. I have set continues deployment solution using Azure DevOps for git repo and CI/CD pipelines with Azure Container Registry (ACR) for storing images. Unfortunately ACR charges some costs each day. I want to use Docker Hub instead.

I went through MS docs and other sites as well, every Azure DevOps Pipeline task and/or 'az containerapp' Azure CLI command I found requires references to ACR, no option for using some other image repo provider. However we can set Docker Hub repo in Azure Portal user interface, so it should probably be achievable. Do you maybe know some way to reach that?

2 Answers2

0

When creating the web app, choose Docker hub image source, then, once created, see the picture bellow for the continue deployment

MPFabio
  • 1
  • 1
0

We can deploy the docker image from the docker hub to Azure container apps using the below command.

az containerapp up -n $(containerapp-name) -g $(resourcegroup-name) --image $(dockerusername)/$(imagename):latest --environment $(environment-name) --ingress external --target-port 80 --registry-username $(dockerusername) --registry-password $(docker-registry-password) --registry-server hub.docker.com --query properties.configuration.ingress.fqdn

We can set up CICD pipeline in Azure as shown below.

Firstly, create a service for docker as below. enter image description here

Next, create a pipeline with the docker task and azure cli task as below. It will build the image, push to docker hub and deploy to azure container apps whenever a new commit is available in main branch.

trigger:
- main

pool:
  vmImage: ubuntu-latest

variables:
  containerapp-name: livingbeingcontainer
  resourcegroup-name: rg
  dockerusername: jhsdgf
  imagename: cimg
  environment-name: livingbeingcontainer-env

steps:
- task: Docker@2
  displayName: buildAndPush
  inputs:
    containerRegistry: 'spn-docker-hub-registry'
    repository: 'jhsdgf/cimg'
    command: 'buildAndPush'
    Dockerfile: 'Dockerfile'
    tags: |
      $(Build.BuildId)
      latest

- task: AzureCLI@2
  displayName: 'Azure CLI '
  inputs:
    azureSubscription: 'spn-04-29-23-azure-cxp'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az config set extension.use_dynamic_install=yes_without_prompt
      
      az containerapp up -n $(containerapp-name) -g $(resourcegroup-name) --image $(dockerusername)/$(imagename):latest --environment $(environment-name) --ingress external --target-port 80 --registry-username $(dockerusername) --registry-password $(docker-registry-password) --registry-server hub.docker.com --query properties.configuration.ingress.fqdn

Verify the pipeline output onceit completes. enter image description here

Next browse the azure container app to see changes.

enter image description here

HowAreYou
  • 605
  • 2
  • 6
  • 1
    Thanks! Unfortunately I stuck - pipeline returns ERROR: (WebhookInvalidParameterValue) The following field(s) are either invalid or missing. Invalid value: "***/{repository}:{tag}": GET https:: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:***/{repository} Type:repository]]: template.containers.{container-app-name}.image. Have you faced that? I found few topics describing MS has issues with docker registry, but solutions does not work e.g. https://stackoverflow.com/questions/74237694/azure-container-app-unable-to-pull-from-private-registry/74239780#74239780 – Mateusz Walecki May 10 '23 at 16:49
  • worth to mention is fact I am using Personal Access Token as registry password. – Mateusz Walecki May 10 '23 at 19:22
  • ok, I have solved that. With container app preconfigured (I have been already using it with ACR) following Azure CLI command works: "az containerapp update -n $(containerAppName) -g $(azureResourceGroup) --image $(registryServer)/$(containerRegistry)/$(imageRepository):$(tag)" I already have dockerhub registry added and configured in container app. Registry server value is equal to 'registry.hub.docker.com'. containerRegistry variable from given command also equals 'registry.hub.docker.com'. Thanks @GoonaBabu for help! – Mateusz Walecki May 10 '23 at 20:46