What does `services:` do in a GitLab job?

BeginnerConceptGitLab CI
Answer

services starts extra containers linked to the job container for the duration of the job, such as PostgreSQL or Redis for integration tests. The service is reachable via its image name as hostname (for example postgres), or a custom alias.

test:
  image: python:3.12
  services:
    - name: postgres:16
      alias: db
  variables:
    POSTGRES_PASSWORD: pw
    DATABASE_URL: postgresql://postgres:pw@db:5432/postgres
  script: pytest
All CI/CD questions Roadmap: GitLab CI/CD

More on GitLab CI