0
votes

I'm trying to use a Docker image as a build agent in an Azure pipeline. I'm using Azure DevOps Server 2019 and Docker Enterprise Edition.

I get this error when the pipeline runs:

##[section]Starting: Initialize containers
##[command]C:\Program Files\Docker\docker.EXE version --format '{{.Server.APIVersion}}'
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/version: open //./pipe/docker_engine: Access is denied. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
'
##[error]Exit code 1 returned from process: file name 'C:\Program Files\Docker\docker.EXE', arguments 'version --format '{{.Server.APIVersion}}''.
##[section]Finishing: Initialize containers

I've verified that Docker is installed on the server. I ran the following commands to make sure Docker is running on the server and all ran successfully:

Start-Service Docker
docker network ls
docker version

Here is the pipeline YAML file I'm using:

trigger:
  none
resources:
  containers:
  - container: angulardocker
    image: mdailey77/angularbuild:1.0
    endpoint: Docker Hub

stages:
  - stage: Client
    jobs:
      - job: BuildTest
        pool:
          name: Default Windows
        container: angulardocker
        steps:
          - task: Npm@1
            displayName: 'Client Build'
            inputs:
              command: custom
              customCommand: run build -- --prod
              workingDir: client
          - task: CopyFiles@2
            displayName: 'Copy Client Build to Staging Directory'
            inputs:
              contents: '**'
              SourceFolder: $(Build.SourcesDirectory)/client/dist
              targetFolder: $(Build.ArtifactStagingDirectory)/client
          - task: PublishBuildArtifacts@1
            displayName: 'Publish Build Artifact - Client'
            inputs:
              pathToPublish: '$(Build.ArtifactStagingDirectory)/client'
              artifactName: 'Client'

The error occurs at the initialization container pipeline step. The Microsoft documentation regarding Docker images as build agents is lacking to say the least. It was no help at all. This post I found had the best example: https://im5tu.io/article/2018/12/building-a-custom-build-agent-image-with-docker-and-azure-devops-pipelines/. I can't figure out the error and stuck at the moment.

UPDATE: After doing more research and @vaibhavnd suggestion, I'm fairly certain the issue is my pipeline build agent doesn't have access to the Docker daemon. True to form, the Microsoft documentation mentions this but doesn't actually show how to do it. How do I configure my build agents so they have access? What would be the steps?

UPDATE 2: I looked into adding a user to the docker-user group, but there is no such group on the server. According to one GitHub post, the docker user group is supposed to be automatically created after installing Docker and doing a restart. I restarted the server and the group still doesn't exist.

1
suggest to check if access rights are in place e.g. if docker is installed as administrator , it may not be available for other usersvaibhavnd
@vaibhavnd In order to install Docker on the server I had to run Powershell as admin. How would I check to see if Docker is available for other users?mdailey77
verifying if "docker ps " command works for current user would do.vaibhavnd
@vaibhavnd I ran 'docker ps' in Powershell as a non admin and got the same error as I did in the pipeline. Do I need to change some kind of setting?mdailey77
glad that able to reproduce , this means that non-admin user doesn't have access to docker, you need to get "non-admin" user added in docker groupvaibhavnd

1 Answers

2
votes

I figured out how to solve the issue. This GitHub post really helped me. I used the dockeraccesshelper mentioned in the post. I granted the account associated with my pipeline build agents, so 'NT AUTHORITY\NETWORK SERVICE' in this case, access to Docker. Once I did this my pipeline was able to initialize the Docker container.

Going the docker-user group route didn't work for me. The docker-user group was not automatically created when I installed Docker Enterprise. I think this might be normal when using Docker Enterprise on Windows Server 2019. I tried creating the group on my own and add the 'NT AUTHORITY/NETWORK SERVICE' account to the group but was unable to add it.