Welp, I invested three days into this, I figured I'll ask.
I boiled my problem down to this:
The app I'm dockerizing is nothing special:
# docker-compose.yml
services:
php:
image: php:8.1.5-fpm-bullseye
volumes:
- ./:/var/www
# this is the end goal: files writable by this image:
nginx:
image: "nginx:1.23-alpine"
ports:
- "8090:80"
volumes:
- .:/var/www
On my host machine the current user has: uid=1000(raveren) gid=1000(raveren)
But the files that end up in the mounted volume belong to root (id=0):
> docker compose exec php ls -l /var/www
total 3900
-rwxrwxr-x 1 root root 21848 Jul 19 11:52 Makefile
-rwxrwxr-x 1 root root 1153 Jul 18 07:03 README.md
# etc etc
How am I supposed to make some of the directories (i.e. cache, log, and potentially much more) writable for the www-data
user that nginx is running on?
If the files belonged to a non-root user I could do that by either changing the www-data
id to match the owner - or do something along the lines of this nice guide.
However, the problem I can't get past is: the containerized files don't "admit" that their owner is actually id=1000 and not root id=0.
I tried:
- All variations of
user
directive - in yaml and Dockerfile userns_mode: "host"
in the yaml.- When I do
docker compose exec chown 1000 testfile
the owner on the host machine gets reflected as 100999. That's why I suspected userns because cat /etc/subuid gives raveren:100000:65536
Please advise!