bitnami / containers

Bitnami container images
https://bitnami.com
Other
3.42k stars 4.88k forks source link

[bitnami/postgresql] Bitnami postgresql permissions #42194

Closed timwr closed 1 year ago

timwr commented 1 year ago

Name and Version

bitnami/postgresql-13-debian-10

What architecture are you using?

arm64

What steps will reproduce the bug?

  1. On Mac M1 docker
  2. Start container with docker-compose

What is the expected behavior?

No response

What do you see instead?

postgresql           | postgresql 09:27:10.43 
postgresql           | postgresql 09:27:10.44 Welcome to the Bitnami postgresql container
postgresql           | postgresql 09:27:10.46 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
postgresql           | postgresql 09:27:10.47 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
postgresql           | postgresql 09:27:10.49 
postgresql           | postgresql 09:27:10.59 INFO  ==>  Starting PostgreSQL setup 
postgresql           | postgresql 09:27:10.81 INFO  ==> Validating settings in POSTGRESQL_* env vars..
postgresql           | postgresql 09:27:10.88 INFO  ==> Loading custom pre-init scripts...
postgresql           | postgresql 09:27:10.92 INFO  ==> Initializing PostgreSQL database...
postgresql           | chmod: changing permissions of '/bitnami/postgresql/data': Permission denied
postgresql           | postgresql 09:27:11.36 WARN  ==> Lack of permissions on data directory!

Additional information

Any ideas? I have tried many things...

javsalgar commented 1 year ago

Hi,

Could you share the docker-compose file you are using?

timwr commented 1 year ago

$ cat docker-compose.yml

version: "3.7"

services:
  # https://hub.docker.com/r/bitnami/postgresql
  # https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md
  helpme-postgresql:
    image: "bitnami/postgresql:13-debian-10"
    container_name: helpme-postgresl
    restart: always
    user: root
    environment:
      POSTGRESQL_REPLICATION_MODE: master
      POSTGRESQL_REPLICATION_USER: user
      POSTGRESQL_REPLICATION_PASSWORD: password
      POSTGRESQL_USERNAME: username
      POSTGRESQL_PASSWORD: password
      POSTGRESQL_DATABASE: database
      ALLOW_EMPTY_PASSWORD: "no"
    entrypoint: 'bash -c "
      echo \"ALTER ROLE username SUPERUSER;\" > /docker-entrypoint-initdb.d/superuser.sql;
      /opt/bitnami/scripts/postgresql/entrypoint.sh /opt/bitnami/scripts/postgresql/run.sh
    "'
    ports:
      - "0.0.0.0:5432:5432"
    networks:
      - backend
    volumes:
      - ./data/postgresql:/bitnami/postgresql
    healthcheck:
      test:
        - CMD
        - pg_isready
        - --dbname=database
        - --quiet
        - --username=username
      interval: 15s
      timeout: 5s
      retries: 6

networks:
  backend:
    name: backend
$ docker-compose up --build
[+] Running 1/1
 ✔ Container helpme-postgresl  Created                                                                                                                                 0.1s 
Attaching to helpme-postgresl
Error response from daemon: error while creating mount source path '/Users/user/dev/docker-postgres/data/postgresql': chown /Users/user/dev/docker-postgres/data/postgresql: permission denied
users-MacBook-Air:docker-postgres user$ chmod -R 777 data/
users-MacBook-Air:docker-postgres user$ docker-compose up --build
Attaching to helpme-postgresl
helpme-postgresl  | postgresql 07:12:29.30 
helpme-postgresl  | postgresql 07:12:29.31 Welcome to the Bitnami postgresql container
helpme-postgresl  | postgresql 07:12:29.32 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
helpme-postgresl  | postgresql 07:12:29.33 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
helpme-postgresl  | postgresql 07:12:29.34 
helpme-postgresl  | postgresql 07:12:29.36 INFO  ==> ** Starting PostgreSQL setup **
helpme-postgresl  | postgresql 07:12:29.52 INFO  ==> Validating settings in POSTGRESQL_* env vars..
helpme-postgresl  | postgresql 07:12:29.72 INFO  ==> Loading custom pre-init scripts...
helpme-postgresl  | postgresql 07:12:29.74 INFO  ==> Initializing PostgreSQL database...
helpme-postgresl  | chown: changing ownership of '/bitnami/postgresql/data': Permission denied
helpme-postgresl exited with code 0

I tried removing user: root but then I get permission denied elsewhere :(

Everything works perfectly on docker on Linux...

carrodher commented 1 year ago

This could be related to the non-root nature of the Bitnami containers (see [1] and [2]). Could you try configuring the proper permission (user 1001, group root) in the local directory where the volume is mounted?

timwr commented 1 year ago

Apologies @carrodher Exactly which commands do I run to ensure the directory has the correct permissions?

sudo chmod -R 777 data

sudo chown -R 1001 data
sudo chgrp -R root data
chgrp: root: illegal group name
sudo chgrp -R wheel data

Despite this, nothing seems to work. Is there anything I can do to make this container work on the Mac M1 docker? Many thanks!

carrodher commented 1 year ago

What is the output of ls -la data?

timwr commented 1 year ago
$ ls -la data
total 0
drwxrwxrwx  3 root  wheel   96 Aug  4 15:16 .
drwxr-xr-x  5 user  staff  160 Aug  4 15:18 ..
drwxrwxrwx  3 root  wheel   96 Aug  4 15:16 postgresql
$ ls -la data/postgresql/
total 0
drwxrwxrwx  3 root  wheel  96 Aug  4 15:16 .
drwxrwxrwx  3 root  wheel  96 Aug  4 15:16 ..
drwxrwxrwx  2 root  wheel  64 Aug  4 15:16 data
$ ls -la data/postgresql/data/
total 0
drwxrwxrwx  2 root  wheel  64 Aug  4 15:16 .
drwxrwxrwx  3 root  wheel  96 Aug  4 15:16 ..

It seems like whatever owner/group/permissions I give, it always fails...

$ ls -la data/
total 0
drwxrwxrwx  3 1001  wheel   96 Aug  4 15:16 .
drwxr-xr-x  5 user  staff  160 Aug  4 15:18 ..
drwxrwxrwx  3 1001  wheel   96 Aug  4 15:16 postgresql
$ ls -la data/postgresql/
total 0
drwxrwxrwx  3 1001  wheel  96 Aug  4 15:16 .
drwxrwxrwx  3 1001  wheel  96 Aug  4 15:16 ..
drwxrwxrwx  2 1001  wheel  64 Aug  4 15:16 data
$ ls -la data/postgresql/data/
total 0
drwxrwxrwx  2 1001  wheel  64 Aug  4 15:16 .
drwxrwxrwx  3 1001  wheel  96 Aug  4 15:16 ..

I think it's something wrong with how Docker on the M1 handles volumes...

carrodher commented 1 year ago

The group should be root, according to the above outputs it is always wheel

github-actions[bot] commented 1 year ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] commented 1 year ago

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.

mike667 commented 1 year ago

@timwr Hello, have you solved your issue? I have same one on my M1 13.6.

mike667 commented 1 year ago

@carrodher Hello, I tried to change folder owner as: sudo chown -R 1001:1001 docker-postgresql sudo chown -R 1001:root docker-postgresql

I cannot set root group because get error: chown: root: illegal group name

And docker container start always fail with reason: mkdir: cannot create directory ‘/bitnami/postgresql/data’: Permission denied

My service config:

version: "3"

services:
  database:
    image: bitnami/postgresql:16.0.0-debian-11-r10
    restart: always
    environment:
      - POSTGRESQL_USERNAME=user
      - POSTGRESQL_PASSWORD=password
      - POSTGRESQL_DATABASE=db
    volumes:
      - ./docker-postgresql:/bitnami/postgresql
    ports:
      - 5432:5432
mike667 commented 1 year ago

For future readers. Solved by run: sudo chown -R $USER:1001 docker-postgresql

Owner must be system user and group 1001

ledaithangdn commented 8 months ago

For future readers. Solved by run: sudo chown -R $USER:1001 docker-postgresql

Owner must be system user and group 1001

@mike667 I used your solution but when I use with 16.2.0-debian-12-r5 it just show log then unexpected exit with no further reason, even I don't see any error log there. Still don't know why :(