【问题标题】:How to disable docker cache while building an image in VSTS build?如何在 VSTS 构建中构建映像时禁用 docker 缓存?
【发布时间】:2018-06-27 11:47:34
【问题描述】:

我正在运行一个包含 docker 构建任务的 VSTS 构建。我在构建参数字段中传递 --no-cache 参数。不幸的是,在构建过程中,我收到一条消息,指出此 arg 被忽略。有人遇到过同样的问题吗?

【问题讨论】:

标签: docker azure-devops azure-pipelines


【解决方案1】:

原因是docker build任务在--build-arg后面加上--no-cache参数,无法消费。

解决方法是您可以添加其他参数,例如test=test --no-cache(警告将是 [test] were notsumption.

另一方面,你也可以通过命令行任务调用docker build命令。

【讨论】:

    【解决方案2】:

    添加 --no-cache 对我不起作用

    我在 Dockerfile 中的 COPY 语句之前添加了一个标记,我不想被缓存

    FROM microsoft/azure-functions-dotnet-core2.0:2.0-nanoserver-1803
    
    ARG CACHEBUSTER=0
    COPY ./FunctionApp/bin/Release/netstandard2.0/Publish /approot
    

    然后在docker build 任务之前放置一个RegEx Replace 任务并将ARG CACHEBUSTER=0 替换为独特的东西,例如ARG CACHEBUSTER=$(Build.BuildNumber)

    【讨论】:

      【解决方案3】:

      在 Azure Build Pipelines 中使用“azure-pipelines.yml”修复了这个问题:

      script: docker build -t $(dockerId)/$(imageName) .  # add options to this command to meet your needs
      

      Build, test, and push Docker container apps in Azure Pipelines - Build an image

      例子:

      pool:
       name: MarkusMeyer
       demands:
       - node.js
       - Agent.OSVersion -equals 10.0.17134
      
      variables:
        imageName: 'your-container-image-name:$(build.buildId)'
      
      steps:
       - script: docker build --no-cache -f Dockerfile -t $(imageName) .
      displayName: 'docker build'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-23
        相关资源
        最近更新 更多