【问题标题】:How can I add /etc/hosts entries to a container executed on an Azure Pipelines build agent如何将 /etc/hosts 条目添加到在 Azure Pipelines 构建代理上执行的容器
【发布时间】:2022-01-26 21:12:28
【问题描述】:

我需要备份连接到虚拟网络并具有自定义域的 Azure API 管理实例的 Git 存储库。因此 SCM 端点例如myapiminstance.scm.azure-api.net 没有有效的公共 DNS 条目,无法解析为其本地 IP 地址,例如10.1.2.3.

因为我不想修改我的构建代理主机名解析,例如为我的虚拟网络实施私有 DNS 我正在寻找一个非常简单的解决方案。

如何使用调整后的/etc/hosts 使 Azure Pipelines 容器运行,以便我可以使用参数或变量组轻松控制 IP 地址和主机名?

【问题讨论】:

    标签: docker azure-pipelines hosts azure-pipelines-yaml azure-pipelines-tasks


    【解决方案1】:

    可以在指定容器时添加docker create 参数--add-host 作为选项:

    name: apim-repo-backup-$(Date:yyyyMMdd)$(Rev:.r)
    
    trigger:
      paths:
        include:
        - apim-repo-backup.yml
        - testHosts.ps1
    
    stages:
      - stage: test
        displayName: test hostname modification
        jobs:
        - job:
          pool:
            name: internal
            demands:
            - Agent.OS -equals Linux
    
          container:
            image: mcr.microsoft.com/azure-powershell:latest
            options: --add-host=myapiminstance.scm.azure-api.net:10.1.2.3
    
          workspace:
            clean: all
    
          steps:
    
          - task: AzurePowerShell@4
            displayName: display hosts
            inputs:
              azureSubscription: 'MySubscription'
              scriptType: filePath
              azurePowerShellVersion: latestVersion 
              scriptPath: 'testHosts.ps1'
    

    testHosts.ps1:

    cat /etc/hosts
    

    输出:

    127.0.0.1   localhost
    ::1 localhost ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    10.1.2.3    myapiminstance.scm.azure-api.net
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      相关资源
      最近更新 更多