How to Run a Job in a Container in Azure Pipelines
The container keyword runs all of a job's steps inside a Docker image instead of directly on the agent.
Set container: on the job to an image reference, or declare it under resources.containers and reference it by alias. Steps then execute inside that container with the tools it provides.
Steps
- Set
container:on the job to the image you want. - For a private registry, declare the container under
resources.containerswith an endpoint. - Run your steps as normal; they execute inside the container.
Pipeline
azure-pipelines.yml
resources:
containers:
- container: builder
image: node:20-bookworm
jobs:
- job: build
pool:
vmImage: ubuntu-latest
container: builder
steps:
- script: node --version && npm ci && npm run buildGotchas
- Container jobs run on Linux agents; Windows container jobs need Windows agents.
- The image needs Node and other dependencies the agent injects for some tasks.
- Use
resources.containerswith an endpoint to pull from a private registry.
Related guides
How to Build and Push a Container Image in Azure PipelinesBuild and push a Docker image from Azure Pipelines with the Docker@2 task, using a container registry service…
How to Run a Bash or PowerShell Script Step in Azure PipelinesRun shell scripts in Azure Pipelines with the Bash@3 and PowerShell@2 tasks, choosing inline scripts or a fil…