1

I'm getting this permission denied from Postgres when I inspect the volume.

My user and databases are not created because of this permission issue. I can confirm this by running command docker exec -it <cont_name> bin/bash and inspect postgres container and there's no user.

It didn't happened before I reformat my mac book so I don't know what happened. I'm running Mac OS Catalina and running latest Docker.

enter image description here

Here's the db service of my yml file

db:
    image: postgres:9.6
    environment:
      - DB_USER=sales_store # used by psql to create rails user
      - DB_PASSWORD=localpostgres # used by psql to create rails user
      - POSTGRES_PASSWORD=localpostgressu # used by psql
      - DB_RESTORE_DATABASE=sales_store_development
    deploy:
      placement:
        constraints: [node.role==manager]
    ports:
      - "5432:5432"
    volumes:
      - db-data:/var/lib/postgresql/data # mount data to host
      - ./init/db/0-init-user-db.sh:/docker-entrypoint-initdb.d/0-init-user-db.sh # database init (fork of sales-store's init)

      # restore from .sql.gz file
      - ./backup/db/sales_store_ist.sql.gz:/1-restore-backup.sql.gz # copy backup file to container
      - ./init/db/1-restore-backup.sh:/docker-entrypoint-initdb.d/1-restore-backup.sh # run psql restore; 
    networks:
      - db-network

What I did to fix this but didn't work:

  • I tried running this command chmod +x docker-entrypoint.sh from this link -- but didn't work

  • I gave read write permission to my volumes folder --- but didn't work


I read this Initialize PostgreSQL Container with docker-entrypoint-initdb.d script

but the author fixes it by altering the yml file. I don't want to do that because I've never done that before and it was running until I reformatted my Mac. I'm assuming it's my Docker, or it's my root folder, and I need to give everyone read and write permission?

halfer
  • 19,824
  • 17
  • 99
  • 186
aRtoo
  • 1,686
  • 2
  • 18
  • 38

1 Answers1

3

The solution is really simple: you just have to give execute permission on shell scripts.

enter image description here

The two .sh files have only read permission so what I did is just run command chmod 777 <file_name>. Every user will now have read write execute. This is not recommended though.

But for me I just need to try it to be sure, since I was desperate. Also I was changing parent folders permission as I thought it will propagate to the sub folders and files.

halfer
  • 19,824
  • 17
  • 99
  • 186
aRtoo
  • 1,686
  • 2
  • 18
  • 38