OffchainLabs / orbit-setup-script

44 stars 71 forks source link

Permission Issue with db-init Service in Docker Compose #62

Open sawakaga opened 8 months ago

sawakaga commented 8 months ago

Hello Maintainers,

Environment: Docker compose version: Docker Compose version v2.24.5-desktop.1 System: MacOS 14.2.1 (23C71) Last Commit when bug happen: 084d1885565c6c0fbb356bb69c43ed3eef0982e5

Steps to Reproduce:

  1. Clone the repository from the main branch.
  2. Execute yarn install.
  3. Copy and paste configurations into the config folder.
  4. Run docker-compose up.
  5. Observe the error during the startup of the db-init-1 service.

Expected Behavior: The db-init-1 service initializes the database without permission errors.

Actual Behavior: The db-init-1 service fails with the following permission error for several files:

 db-init-1  | chown: changing ownership of '/var/lib/postgresql/data/._pg_subtrans': Operation not permitted

Additional Information

After investigating the problem, I found that official postgres docker image README has a part for using arbitrary user usage for postgres.

$ docker volume create pgdata
$ docker run -it --rm -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=mysecretpassword postgres
The files belonging to this database system will be owned by user "postgres".
( once it's finished initializing successfully and is waiting for connections, stop it )
$ docker run -it --rm -v pgdata:/var/lib/postgresql/data bash chown -R 1000:1000 /var/lib/postgresql/data
$ docker run -it --rm --user 1000:1000 -v pgdata:/var/lib/postgresql/data postgres
LOG:  database system was shut down at 2017-01-20 00:03:23 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections

This guide solves the problem.

P.S

On db.yml, stats.yml and docker-compose.yml, db-init services commented out

IMHO

My take on this bug is, db-init does not allow db to initialise before runs the "sh -c chown ***" command.

Probably, it is something different causes the bug but above solution helped me out to proceed. Step-by-step guide on the README currently stuck at second step.

I hope it helps.

ReyanCarlier commented 7 months ago

The actual error is due to the fact that database isn't initialised and superuser password isn't specified. See : https://www.postgresql.org/docs/current/auth-trust.html