How to setup docker rootless compose with the apache php image and bind mount? (file owner)

thans for your respons Ákos,

in the mean time i did already understand this behavior.

i also found a really interesting information regarding this:
you can use

rootlesskit -- chown -R www-data:www-data my-app-data

on the host to set the files to a user as owner that belongs to the container!

This translates the id mapping and setts them in the right way.
and you do not need superuser rights to do it!
so that is exactly the tool i need for my setup.

this leads to something like

$ ls -lah
total 72K
drwxrwxr-x  6 web1   web1   4,0K 15. Jun 13:26  ./
drwxr-xr-x 16 web1   root   4,0K 14. Jun 13:46  ../
-rw-rw-r--  1 web1   web1   2,5K 15. Jun 14:17  docker-compose.yml
-rw-rw-r--  1 web1   web1    230 28. Mai 03:14  .editorconfig
-rw-rw-r--  1 web1   web1     89 28. Mai 13:10  .env
-rw-rw-r--  1 web1   web1    976 15. Jun 13:36  .gitignore
drwxrwxr-x  8 493248 493248 4,0K 14. Jun 22:00  my-app-data/
-rw-rw-r--  1 web1   web1    200 10. Jun 22:08  README.md

see the cryptic ID 493248 -
if you wish you can add a user that has this id to have a nicer listing view:

sudo groupadd --system  --gid 493248 drl-www-data
sudo useradd --system --no-create-home --uid 493248 --gid 493248 --comment "docker-rootless www-data" drl-www-data

(drl for docker-rootless)

for this you need superuser rights. (at least as fare as i know there is no other way…)

to change the file user back to your host user you can do:

rootlesskit chown -R root:root my-app-data

for me this is a solution i can live with :slight_smile:

sunny greetings
stefan

1 Like