Docker 构建在 Azure Dev Ops 自托管代理中失败

时间:2021-07-20 14:59:11

标签: docker azure-devops azure-pipelines azure-devops-self-hosted-agent

背景

我已经在我的 AKS 集群中设置了一些自托管的 Azure Devops 构建代理。这是文档:https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops

代理已成功创建,我可以在我的代理池中看到它们并从我的管道中定位它们。

我的管道做的第一件事就是构建和推送一些 docker 镜像。这是自托管代理内部的问题。该文档包括以下警告和链接:

<块引用>

为了在 Docker 容器中使用 Docker,您需要绑定挂载 Docker 套接字。 如果您确定要执行此操作,请参阅 Docker.com 上的绑定挂载文档。

文件

Kubernetes 部署

apiVersion: apps/v1
kind: Deployment
metadata:
  name: azdevops-deployment
  labels:
    app: azdevops-agent
spec:
  replicas: 1 #here is the configuration for the actual agent always running
  selector:
    matchLabels:
      app: azdevops-agent
  template:
    metadata:
      labels:
        app: azdevops-agent
    spec:
      containers:
      - name: kubepodcreation
        image: AKRTestcase.azurecr.io/kubepodcreation:5306
        env:
          - name: AZP_URL
            valueFrom:
              secretKeyRef:
                name: azdevops
                key: AZP_URL
          - name: AZP_TOKEN
            valueFrom:
              secretKeyRef:
                name: azdevops
                key: AZP_TOKEN
          - name: AZP_POOL
            valueFrom:
              secretKeyRef:
                name: azdevops
                key: AZP_POOL
        volumeMounts:
        - mountPath: /var/run/docker.sock
          name: docker-volume
      volumes:
      - name: docker-volume
        hostPath:
          path: /var/run/docker.sock

错误

尝试运行管道给了我以下错误:

##errorUnhandled:无法定位可执行文件:'docker'。请验证文件路径是否存在,或者可以在 PATH 环境变量指定的目录中找到该文件。还要检查文件模式以验证文件是否可执行。

问题

  1. 是否可以(并且安全)从在 docker 容器中运行的 Azure Devops 构建代理构建和推送 docker 镜像?
  2. 如何修改 Kubernetes 部署文件,以绑定挂载 docker 套接字。

任何帮助将不胜感激。

0 个答案:

没有答案