skip to Main Content

I have a problem with docker-compose postgreSQL, I am working on Windows WSL 2 + Docker Desktop. When I run docker-compose on linux server it works good, but when I try to start it locally I’m getting next error:

postgres      | chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted
ngnix         | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
postgres      | The files belonging to this database system will be owned by user "postgres".
postgres      | This user must also own the server process.
postgres      |
postgres      | The database cluster will be initialized with locale "en_US.utf8".
postgres      | The default database encoding has accordingly been set to "UTF8".
postgres      | The default text search configuration will be set to "english".
postgres      |
postgres      | Data page checksums are disabled.
postgres      |
ngnix         | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
ngnix         | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
postgres      | fixing permissions on existing directory /var/lib/postgresql/data ... initdb: error: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
ngnix         | /docker-entrypoint.sh: Configuration complete; ready for start up
postgres exited with code 1

I tried to change permission on all project like this => chmod 777 -R project_folder

Dcoker-compose.yml:

postgresdb:
    container_name: postgres
    build:
      context: ./docker/postgres
      dockerfile: Dockerfile
    environment:
      - POSTGRES_PASSWORD=password123
    volumes:
    - ./docker/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
    - ./postgres-data:/var/lib/postgresql/data

    ports:
    - "5432:5432"

No ideas, how to resolve it. Help me please!

2

Answers


  1. So my guess here is, that since you are mounting a directory relative to the docker-compose file as "data" directory in WSL, the permission error occurs. You can try to fix these permissions (chmod, chown etc the local directory).

    You could also use "named" volumes – which should get rid of the permission problem as well.

    # docker-compose.yml
    
    services:
      # ...
      db:
        image: postgres:latest
        volumes:
          - "dbdata:/var/lib/postgresql/data"
    
    volumes:
      dbdata:
    
    Login or Signup to reply.
  2. My solution is to start build from Windows PowerShell, then there is no issue with permissions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search