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
More on GitLab CI
How does GitLab CI/CD work at a high level?BeginnerWhat is a GitLab Runner and what executors exist?IntermediateWhat are the types of runners (shared, group, project) and tags?IntermediateHow do `rules:` work and how do they replace `only/except`?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedHow do artifacts and cache differ in GitLab CI?Intermediate