Deploy image from Azure Container Registry to an Azure Linux Virtual Machine

2.8k views Asked by At

I have created a build-pipeline which builds my docker based project. The image is being pushed to the Azure Container Registry.

What I want to achieve is to deploy the image to a virtual machine but I have no idea where to start. Do I for example need to create a release pipeline which executes a script on the virtual machine which results in the image being pulled and run?

Hope some can help me out with this one.

2

There are 2 answers

0
Levi Lu-MSFT On BEST ANSWER

If you want to automate the process to deploy the image to a virtual machine via azure pipeline. You need to create a pipeline, or add an additional agent job or step which executes the dock commands on the virtual machine to your existing pipeline. Check out below possible workarounds:

1, Create a self-hosted agent on the virtual machine. See tutorial here for detailed steps.

Then you can add an additional agent job or create a release pipeline to run the docker commands in a script task. And configure the agent pool to run the job on your self-hosted agent pool.

For below example. I add an additional job and execute the docker commands in a powershell task to run the image:

stages:
- stage: 
  jobs: 
  - job: Build
    steps:
    ...

  - job: Deploy
    dependsOn: Build
    pool: Default  #run this job on the self-hosted agent which is hosted on the VM.
    steps:
    - powershell: |
        docker login CONTAINERREGISTRYURL -u CONTAINERREGISTRYNAME -p CONTAINERREGISTRYPASSWORD
        docker run ....

2, If you donot want to create a self hosted agent. You can also try using one of below tasks in your pipeline, which allow you run the dock scripts on the target Virtual machine.

PowerShell on Target Machines task

SSH Deployment task

0
Charles Xu On

Do I for example need to create a release pipeline which executes a script on the virtual machine which results in the image being pulled and run?

Actually, yes. As you said, you want to deploy the image in the virtual machine. It means you treat the VM as a docker server and run containers in it, then you need to execute the commands inside it. So the steps would like this:

  1. Install and configure the Docker server;
  2. Login the Azure Container Registry;
  3. Pulled the image from Azure Container Registry;
  4. Deploy the image in the VM.

In my side, execute a script with all the commands is better then execute the commands separately.