I am running docker-compose in Github-Action. docker-compose.yml
has following service definition for 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"
But when container start on serf-hosted Github-Action runner, I see following
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
What is missing here ?
2
Answers
I’m getting a similar error when trying to run a pg_restore on the postgresql docker container, I had set up postgresql on docker-compose and was trying to restore a db (from my prev postgresql) to it. Just had the initial user as "postgres". Some errors I’d get:
pg_restore: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: role "root" does not exist
createuser: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "root" does not exist
On research I found my pg_restore command needed to specify the User for it to work (tried specifying role, that failed)
Here’s the working pg_restore command. Perhaps you can do similarly and find a way to specify user in yours?
should set POSTGRES_DB and POSTGRES_USER in healthcheck