1
votes

I am running a Docker task 'buildAndPush'in Azure Pipeline yaml file, to build my repository image and push to ACR. This work perfectly fine and i could see my image in docker and ACR.

However, I want to break this task. I want to build the image in docker. I want to run the docker image locally once, then run the test script in the docker image (a python file). Only after the test results are successful, I should be pushing this to ACR.

So I started with the build task.

  - task: Docker@2
    inputs:
      containerRegistry: 'mycontainerRegistry'
      repository: 'myrepository'
      command: 'build'
      Dockerfile: '**/Dockerfile'
      tags: $(Build.BuildId) 

This successfully builds my image. Now I run a bash command to list my images.

- bash: docker image ls

I could see my image built but it shows as '***/myrepository' . This is where the problem lies.

I want to use this image and run my newly built docker image to ensure the run completes successfully

- bash: docker run 'myrepository:$(Build.BuildId)'

I get the error that repo not found. The Build id is correct as I see it in the images tag. I cannot use docker run ***/myrepository:$(Build.BuildId) as it throws an error incorrect format.

[error]invalid argument "***/myrepository:7167" for "-t, --tag" flag: invalid reference format

Is there a way to resolve this. Is this the right approach I am following?

Thanks for your time!

1
Are you sure that the *** isn't a masked secret?Daniel Mann
I did not provide a secret nor using custom variables or Keyvault here. Thanks!Suraj
@DanielMann The acr uri was getting masked. Thanks for your inputSuraj

1 Answers

3
votes

When you connect your docker build task to ACR. The docker image will be prefixed by your registry URI. The *** in ***/myrepository is your registry URI encrypted.

So you need to specify your image as Your_ACR_URI/myrepository:$(Build.BuildId) in the docker run command. See below example:

- bash: docker run 'leviacr.azurecr.io/alpinelevi:$(Build.BuildId)'