I'm not building images Im just using a public image for the agent.
For example:
resources:
containers:
- container: test
image: amazon/aws-cli:latest
jobs:
- job: RunInContainer
container: test
steps:
- script: echo testing....
It downloads amazon/aws-cli:latest
every single time. How do I enable the image cache? I tried to google this but all the information is about caching images your build yourself.
I don't want to use self-hosted runners. I'm specifically asking if this is possible with out self-hosting.
When using a Microsoft-provided build agent, you get a brand new machine for each pipeline job. Regardless if the image could be cached, the image needs to be downloaded to the agent each time.
As you've mentioned, the Cache@2
pipeline task can be used to create a cached set that can be downloaded to the machine. If that cached set takes a long time to resolve from external sources or is the by-product of a lengthy activity, using the cache in this manner can speed up the build-process by eliminating some of the lengthy process, but the cached data still needs to be downloaded at the start of the pipeline job.
The Cache@2
task is the only mechanism that exposes the internals of the cache to the pipeline. While you could build an image as part of the pipeline, export it as a tar and then use the cache task to create a reusable asset that could be rehydrated back into an image between pipeline runs, you cannot use an image of this kind as a declared resource
. To declare and use a container
resource, the image would need to exist in a container registry. Because the image won't be on the Microsoft provided agent, it will always be downloaded. This list of images available on the ubuntu 24.04 image is listed here.
This is the trade-off between Microsoft-provided and self-hosted agents. Microsoft-provided agents are maintenance free and produce deterministic builds without side-effects, but there is an overhead of installing the dependencies fresh every time. Self-hosted agents can be pre-configured to include specialized tools and images which reduces the build duration, but are subjected to side-effects and additional maintenance overhead.
As an alternative to self-hosting, the middle ground is the new Managed DevOps pools offering, which is similar to Microsoft-provided agents but provides the ability for you to bring your own disk image. Managed DevOps pools use pre-built disk images, so it's possible to pre-install the desired container images onto the device so that they do not need to be downloaded on each pipeline run.