How do you run a job inside a container image, and what changes?
IntermediateConceptWorkflow Anatomy & Execution Model
Answer
jobs:
test:
runs-on: ubuntu-24.04
container:
image: node:22-bookworm
options: --user 1001
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test
All run steps and JavaScript actions execute inside that container; the workspace is mounted in. Works only on Linux runners. You lose some preinstalled tools from the host image, and the container may run as root, which can leave root-owned files in the workspace on self-hosted runners.
More on Workflow Anatomy & Execution Model
Define workflow, run, job, step, action and runner in one line each.BeginnerWhat is the minimum valid workflow file?BeginnerWhere must workflow files live, and does the file extension matter?BeginnerWhich version of the workflow file does GitHub use for a given run?IntermediateWhat does a GitHub-hosted runner give you at the start of a job?BeginnerShould you use `ubuntu-latest` or `ubuntu-24.04`?Beginner