我正在Github-Action中运行docker-compose。 docker-compose.yml为postgres定义了以下服务:
postgres:
container_name: postgres
image: postgres:12
restart: always
volumes:
- ./test/data/init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
POSTGRES_DB: "pgdb"
POSTGRES_USER: "pguser"
POSTGRES_PASSWORD: "fr2Yitl4BgX"
ports:
- "${POSTGRES_PORT:-5432}:5432"
healthcheck:
test: [ "CMD-SHELL", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5
networks:
- "local-api"
但是当容器在托管于Serf的Github Actions Runner上启动时,我看到以下信息:
postgres | 2021-12-02 19:48:33.537 UTC [414] FATAL: role "root" does not exist
postgres | 2021-12-02 19:48:43.984 UTC [424] FATAL: role "root" does not exist
postgres | 2021-12-02 19:48:54.265 UTC [433] FATAL: role "root" does not exist
postgres | 2021-12-02 19:49:04.410 UTC [443] FATAL: role "root" does not exist
这里缺少什么?
test: [ "CMD-SHELL", "pg_isready" ]
。没有使用-U
的pg_isready
将使用系统用户作为数据库用户。在这种情况下,执行该命令的系统用户很可能是root
。pg_isready
基于libpq
,因此它将识别适当的环境变量,对于用户来说是PGUSER
,而不是POSTGRES_USER
,详见 libpq env。 - Adrian Klaver"pg_isready -U pguser"
或者在environment
部分添加PGUSER: pguser
。就像我说的,我不是 Docker 用户,所以这只是最好的猜测。 - Adrian KlaverPGUSER
并在pg_isready
命令中添加-U pguser
,但是它没有起作用。 - Hantsy