简体   繁体   English

在 Azure 管道中使用 Docker 映像作为构建代理时出错

[英]getting errors when using Docker image as build agent in Azure pipeline

I'm trying to use a Docker image as a build agent in an Azure pipeline.我正在尝试使用 Docker 映像作为 Azure 管道中的构建代理。 I'm using Azure DevOps Server 2019 and Docker Enterprise Edition.我正在使用 Azure DevOps Server 2019 和 Docker 企业版。

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.我已经验证 Docker 安装在服务器上。 I ran the following commands to make sure Docker is running on the server and all ran successfully:我运行了以下命令以确保 Docker 正在服务器上运行并且全部运行成功:

Start-Service Docker
docker network ls
docker version

Here is the pipeline YAML file I'm using:这是我正在使用的管道 YAML 文件:

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.至少可以说缺乏将 Docker 映像作为构建代理的 Microsoft 文档。 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/ .我发现这篇文章有最好的例子: 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.更新:在做了更多研究和@vaibhavnd 建议之后,我相当确定问题是我的管道构建代理无法访问 Docker 守护进程。 True to form, the Microsoft documentation mentions this but doesn't actually show how to do it.与形式一样,Microsoft 文档提到了这一点,但实际上并没有说明如何做到这一点。 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.更新 2:我考虑将用户添加到 docker-user 组,但服务器上没有这样的组。 According to one GitHub post , the docker user group is supposed to be automatically created after installing Docker and doing a restart.根据一篇 GitHub 帖子,应该在安装 Docker 并重新启动后自动创建 docker 用户组。 I restarted the server and the group still doesn't exist.我重新启动了服务器,该组仍然不存在。

I figured out how to solve the issue.我想出了如何解决这个问题。 This GitHub post really helped me.这篇GitHub 帖子真的帮助了我。 I used the dockeraccesshelper mentioned in the post.我使用了帖子中提到的dockeraccesshelper。 I granted the account associated with my pipeline build agents, so 'NT AUTHORITY\\NETWORK SERVICE' in this case, access to Docker.我授予与我的管道构建代理关联的帐户,因此在本例中为“NT AUTHORITY\\NETWORK SERVICE”,可以访问 Docker。 Once I did this my pipeline was able to initialize the Docker container.一旦我这样做了,我的管道就能够初始化 Docker 容器。

Going the docker-user group route didn't work for me.走 docker-user 组路线对我不起作用。 The docker-user group was not automatically created when I installed Docker Enterprise.我安装 Docker Enterprise 时没有自动创建 docker-user 组。 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.我认为在 Windows Server 2019 上使用 Docker Enterprise 时这可能是正常的。我尝试自己创建组并将“NT AUTHORITY/NETWORK SERVICE”帐户添加到组中,但无法添加它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Docker 映像作为 azure 管道构建代理时出现“找不到模块” - Getting 'module not found' when using Docker image as azure pipeline build agent 在 Azure DevOps 管道中使用 docker/buildx 构建多体系结构映像 - Build multi architecture image using docker/buildx in Azure DevOps pipeline 从 Azure 管道任务构建一个 docker 图像 - Build a docker image from Azure Pipeline Task 使用 Azure 管道构建 docker 图像时找不到 .csproj 文件 - .csproj file not found when building docker image using Azure Pipeline 以root身份运行代理docker时,Jenkins Build Pipeline deleteDIR()问题 - Jenkins Build Pipeline deleteDIR() issue when running agent docker as root 在 azure 构建管道中,一旦推送自托管代理,如何清理 docker 图像(作为管道的一部分创建)? - In the azure build pipeline, how to cleanup the docker images (created as part of the pipeline) from self hosted agent once it is pushed? 从在构建代理上运行的Docker映像连接到Azure Artifacts Feed - Connect to Azure Artifacts Feed from docker image running on build agent 当我将docker任务添加到Azure构建管道时构建失败 - build failed when I added docker task to azure build pipeline Docker 映像构建在 Azure DevOps 发布管道中失败 - Docker image build fails in Azure DevOps release pipeline 构建容器后如何从 Azure 管道中提取 Docker 映像 - How to pull a Docker image from the Azure pipeline after build a container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM