We are developing an ASP.NET app on windows, which runs in docker. When using docker desktop, it "all just works". But a few of us are used to develop in Linux and prefer to work with WSL instead (I understand that docker desktop also relies on WSL, but we just prefer to be able to do "everything" through CLI).
It all works fine, except the volume mapping are causing problems. When we have this (simplified) docker compose as example
timescale-db:
container_name: timescale
image: timescale/timescaledb:latest-pg16
environment:
# some env vars
volumes:
- ./dbdata:/var/lib/postgresql/data
The folder "dbdata" will be created on the windows host in the current directory. docker compose is ran inside WSL, and it will execute in my case in /mnt/c/Users/bpr/dev/iai.productionmaster.central/
In WSL, the path /mnt/c/Users/bpr/dev/iai.productionmaster.central/dbdata is then mapped to the docker container in /var/lib/postgresql/data.
So far so good. But, when the postgress instance then starts, it wants to change permissions on its /var/lib/postgresql/data folder, which fails
initdb: error: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted 2025-08-04T12:29:08.635400362Z fixing permissions on existing directory /var/lib/postgresql/data ... 2025-08-04T12:29:21.768621211Z chmod: /var/lib/postgresql/data: Operation not permitted 2025-08-04T12:29:21.778706750Z
According to several posts (e.g. this one) this has everything to do with NTFS permissions getting in the way.
So when the "host" part of the volume mapping is inside the NTFS mount, I can run into this kind of problems. When I would change the volume mapping to something like "/home/test:/var/lib/postgresql/data", it also works just fine. But then I would need to navigate to \wsl$\home\test to see the contents. Again, not a big issue, but we are trying to get as close as possible to what docker desktop does.
The obvious solution sudo chmod -R 777 /mnt/c/Users
does not solve anything.
Does anybody recognize this problem and do you have a solution to this problem?
The folder "dbdata" will be created on the windows host in the current directory.
Given that you are using WSL and Docker Desktop, I would suggest using named volumes rather than bind mounts here. Unless you need to manually manipulate postgres's files, having postgres keep its data on C:\ is less performant and more complex without gaining anything in return. (e.g. every write in Linux must be translated to a Windows-style file write.)
Here's an example of how you might do this:
services:
timescale-db:
# Other values are the same
# ...
volumes:
- timescale-db-data:/var/lib/postgresql/data
volumes:
timescale-db-data: