I experienced this issue when working on deploying a docker image to a virtual machine on Azure using Azure DevOps.
My initial Azure DevOps pipeline script was:
- stage: Deploy
displayName: Deploy to VM
jobs:
- job: Deploy_to_VM
displayName: Deploy to Virtual Machine
steps:
- task: AzureCLI@2
displayName: Connect to Azure and deploy
inputs:
azureSubscription: $(AzureSubscription)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'az vm run-command invoke -g $(rGroup) -n $(vmName) --command-id RunShellScript --scripts "docker pull $(containerRegistry).azurecr.io/$(imageName):$(tag) && docker service update --replicas=1 --force --image $(containerRegistry).azurecr.io/$(imageName):$(tag) $(imageName)_app"'
Here's how I fixed it:
Adding the command az acr login --name $(containerRegistry)
to the az vm run-command
did the trick`
- stage: Deploy
displayName: Deploy to VM
jobs:
- job: Deploy_to_VM
displayName: Deploy to Virtual Machine
steps:
- task: AzureCLI@2
displayName: Connect to Azure and deploy
inputs:
azureSubscription: $(AzureSubscription)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'az vm run-command invoke -g $(rGroup) -n $(vmName) --command-id RunShellScript --scripts "az acr login --name $(containerRegistry) && docker pull $(containerRegistry).azurecr.io/$(imageName):$(tag) && docker service update --replicas=1 --force --image $(containerRegistry).azurecr.io/$(imageName):$(tag) $(imageName)_app"'