【发布时间】:2020-11-19 15:14:35
【问题描述】:
我正在尝试使用 Docker 映像作为 Azure 管道中的构建代理。我正在使用 Azure DevOps Server 2019 和 Docker 企业版。
管道运行时出现此错误:
##[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
我已验证 Docker 已安装在服务器上。我运行了以下命令以确保 Docker 正在服务器上运行并且全部成功运行:
Start-Service Docker
docker network ls
docker version
这是我正在使用的管道 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'
错误发生在初始化容器管道步骤。 Microsoft 文档中关于 Docker 镜像作为构建代理的文档至少可以说是缺乏的。这根本没有帮助。我发现这篇文章有最好的例子:https://im5tu.io/article/2018/12/building-a-custom-build-agent-image-with-docker-and-azure-devops-pipelines/。我无法弄清楚错误并卡在了那一刻。
更新: 在做了更多研究和@vaibhavnd 建议之后,我相当确定问题是我的管道构建代理无法访问 Docker 守护进程。确实如此,Microsoft 文档提到了这一点,但实际上并没有说明如何做到这一点。如何配置我的构建代理以便他们可以访问?步骤是什么?
更新 2: 我考虑将用户添加到 docker-user 组,但服务器上没有这样的组。根据one GitHub post 的说法,docker 用户组应该是在安装 Docker 并重新启动后自动创建的。我重启了服务器,组还是不存在。
【问题讨论】:
-
建议检查访问权限是否到位,例如如果 docker 以管理员身份安装,其他用户可能无法使用它
-
@vaibhavnd 为了在服务器上安装 Docker,我必须以管理员身份运行 Powershell。如何检查 Docker 是否可供其他用户使用?
-
验证“docker ps”命令是否对当前用户有效。
-
@vaibhavnd 我以非管理员身份在 Powershell 中运行 'docker ps' 并得到与管道中相同的错误。我需要更改某种设置吗?
-
很高兴能够重现,这意味着非管理员用户无权访问docker,您需要将“非管理员”用户添加到docker组中
标签: docker azure-devops azure-pipelines