How to Enable Docker layer caching in Azure DevOps

后端 未结 3 933
日久生厌
日久生厌 2021-02-09 14:20

I am running the below yaml script to build docker images and push into kubernetes cluster but at the same time I wanted to enable docker layer caching in the azure DevOps while

3条回答
  •  [愿得一人]
    2021-02-09 15:16

    Docker layer caching is not supported in azure devops currently. The reason is stated as below:

    In the current design of Microsoft-hosted agents, every job is dispatched to a newly provisioned virtual machine. These virtual machines are cleaned up after the job reaches completion, not persisted and thus not reusable for subsequent jobs. The ephemeral nature of virtual machines prevents the reuse of cached Docker layers.

    1,However, Docker layer caching is possible using self-hosted agents. You can try creating your on-premise agents to run your build pipeline.

    You may need to disable the Job's option 'Allow scripts to access the OAuth token'. For $(System.AccessToken) is passed to docker build using a --build-arg ACCESS_TOKEN=$(System.AccessToken), and its value varies for every run, which will invalid the caching.

    2,You can also you use Cache task and docker save/load commonds to upload the saved docker layer to azure devops server and restore it on the future run. Check this thread for more information.

    3,Another workaround as described in this blog is to use --cache-from and --target in your dockerfile.

    If above workaround is not satisfying. You can submit a feature request to Microsoft Develop Team. Click Suggest a Feature and choose Azure Devops.

提交回复
热议问题