Skip to content
Latchkey

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.containers with 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 build

Gotchas

  • 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.containers with an endpoint to pull from a private registry.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →