GitHub Actions: Jobs, Steps, Matrix, and Reusable Building Blocks/Start a PostgreSQL service container
Run integration tests against a database service.
Section: Matrix, reuse, and services
Start a PostgreSQL service container
yaml
yaml
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5Explanation
Service containers make it easy to run databases and dependent services inside CI.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Matrix, reuse, and services
Test across multiple Node versions
Use a strategy matrix for version coverage.
Run on multiple operating systems
Validate portability across Linux, macOS, and Windows.
Call a reusable workflow
Centralize shared CI logic in one workflow file.
Composite action metadata
Bundle repeated shell steps into a reusable local action.