| 写法 | jobs.<id>.services.<name> |
|---|---|
| 端口 | 映射为宿主端口 |
| 健康检查 | options 中配置 --health-cmd 等 |
| 访问 | 宿主作业用 localhost,容器作业用服务名 |
Postgres 服务
Postgres 服务
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: test
ports: [5432:5432]
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- run: PGPASSWORD=test psql -h localhost -U postgres -c 'select 1'健康检查不充分会出现偶发连接失败:等就绪再跑测试是稳定性关键。