Postgres volume mounting on WSL2 and Docker desktop: Permission Denied on PGDATA folder Postgres volume mounting on WSL2 and Docker desktop: Permission Denied on PGDATA folder docker docker

Postgres volume mounting on WSL2 and Docker desktop: Permission Denied on PGDATA folder


This has got nothing to do with PostgreSQL. Docker containers run as root and so any directory created by Docker will also belong to root.


When you attach to the container and list the directory under /var/lib/postgresql/data it shows postgres as the owner.

Check "Arbitrary --user Notes" section in the official documentation here

The second option "bind-mount /etc/passwd read-only from the host" worked for me.


Two things that were blocking us working with WSL2 on Windows were:

  1. Folder c:\Program files\WindowsApps didn't have admin account listed as owner
  2. McAfee was blocking the WSL. In order to disable blocking we had to remove following rule: Open McAfee -> Threat Prevention -> Show Advanced (button in Right upper corner) -> scroll down to Rules -> name of the rule is "Executing Subsystem for Linux"