dockerazure-devopsazure-pipelinesdevcontainer

How can I give a containerRegistry to a DevcontainersCi task in an Azure DevOps YAML Pipeline?


How can I give a containerRegistry to a DevcontainersCi task in an Azure DevOps YAML Pipeline, like in a Docker@2 task?

Currently pushing from this task fails, apparently due to missing authentication (understandable).

The property containerRegistry like in the Docker@2 task is not accepted by the DevcontainersCi task task.

Or is there another task which allows me to achieve the same, which is to also get the features from the devcontainer already included?


Solution

  • Based on the documentation of the "Dev Container Build and Run Task" extension, the DevcontainersCi@0 task does not provide an input to receive the Docker Registry service connection.

    To connect with a Docker registry, you must add a step before the DevcontainersCi@0 task to login the registry at first.

    1. If you have an existing Docker Registry service connection set to connect with the target Docker registry, you can use a Docker@2 task to run the login with the Docker Registry service connection.

      steps:
      - task: Docker@2
        displayName: 'Docker Login'
        inputs:
          containerRegistry: 'Name of the Docker Registry service connection' 
          command: login
      
      - task: DevcontainersCi@0
        displayName: 'Build and Run Dev Container'
        inputs:
          imageName: registry/imageName
          imageTag: 'tag1, tag2'
          push: filter
          sourceBranchFilterForPush: refs/heads/main
          noCache: false
      
    2. If you do not have a Docker Registry service connection, you can create one for use. Or as @Miao Tian-MSFT suggested, you can use a script task to directly run the "docker login" command with your username and password.

    If using the script task to directly run the "docker login" command, you need to provide and store your username and password as variables in the pipeline. For the security of your sensitive information, I recommended you use the method #1 that login to the Docker registry with a Docker Registry service connection.