A job must run with a specific Docker image and connect to a service container.
BeginnerScenarioGitLab CI
Answer
Situation read → Services in GitLab.
What I'd do →
test:
image: python:3.12
services:
- name: postgres:16
alias: db
variables:
POSTGRES_PASSWORD: test
DATABASE_URL: postgresql://postgres:test@db:5432/postgres
script: pytest
Why → Services are reachable via their alias hostname on the job network.
Interview tip → Add a readiness wait; the service may not be accepting connections when the script starts.
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