-1
  • My computer is running Windows 10 and Docker for Windows
  • I am using docker volume to code faster
  • the code is on the windows side. In the docker-compose.yaml I mount my workspace on the host tho the root of the apache server on the guest
volumes:
    - ./:/var/www/html
  • When I create the file web\modules\custom\hello_world\hello_world.info.yml on the host that file replicates on the guest side but remains empty:
PS C:\Users\jeanp\CONSULTANT\dockertest> docker exec -it my_drupal9_project_nginx /bin/bash
/var/www/html$ ls -al web/modules/custom/hello_world/
total 8
drwxr-xr-x    2 root     root          4096 Aug  3 16:46 .
drwxr-xr-x    3 root     root          4096 Aug  3 16:46 ..
-rwxr-xr-x    1 root     root             0 Aug  3 16:46 hello_world.info.yml
  • (hello_world.info.yml has 0 bytes length and can be edited only by root)
    • On the guest side, when I try to edit hello_world.info.yml I cannot save it because it is marked as read-only
web/modules/custom/hello_world/hello_world.info.yml [Readonly] 0/0 100%
  • On the guest side I asked who am I the answer is wodby:
/var/www/html$ whoami
wodby
  • the other files on in the image on the guest belongs to wodby
/var/www/html$ ls -al web
total 84
drwxr-xr-x    7 wodby    wodby         4096 Jul 22 02:17 .
drwxr-xr-x    4 wodby    wodby         4096 Jul 31 12:04 ..
-rw-r--r--    1 wodby    wodby         1025 Jul 22 02:17 .csslintrc
-rw-r--r--    1 wodby    wodby          151 Jul 22 02:17 .eslintignore
-rw-r--r--    1 wodby    wodby           41 Jul 22 02:17 .eslintrc.json
-rw-r--r--    1 wodby    wodby         2314 Jul 22 02:17 .ht.router.php
-rw-r--r--    1 wodby    wodby         7572 Jul 22 02:17 .htaccess
-rw-r--r--    1 wodby    wodby           94 Jul 22 02:17 INSTALL.txt
-rw-r--r--    1 wodby    wodby         3205 Jul 22 02:17 README.md
-rw-r--r--    1 wodby    wodby          315 Jul 22 02:17 autoload.php
drwxr-xr-x   12 wodby    wodby         4096 Jul 20 21:42 core
-rw-r--r--    1 wodby    wodby         1507 Jul 22 02:17 example.gitignore
-rw-r--r--    1 wodby    wodby          549 Jul 22 02:17 index.php
drwxr-xr-x    3 wodby    wodby         4096 Aug  3 16:46 modules
drwxr-xr-x    2 wodby    wodby         4096 Jul 22 02:17 profiles
-rw-r--r--    1 wodby    wodby         1586 Jul 22 02:17 robots.txt
drwxr-xr-x    3 wodby    wodby         4096 Jul 22 02:17 sites
drwxr-xr-x    2 wodby    wodby         4096 Jul 22 02:17 themes
-rw-r--r--    1 wodby    wodby          804 Jul 22 02:17 update.php
-rw-r--r--    1 wodby    wodby         4016 Jul 22 02:17 web.config

My question is the following:

how to make that on the guest the files created through synchronisation from the host belongs to wodby and not root ?

Jean-Pierre Mena
  • 131
  • 2
  • 12

1 Answers1

1

Sounds like you could benefit from setting up the folder and permissions via the Dockerfile prior to mounting the files in:

https://github.com/moby/moby/issues/2259#issuecomment-48286811

Else this issue may be able to help you out, detailing a volumes-from pattern

What is the (best) way to manage permissions for Docker shared volumes?

TheQueenIsDead
  • 865
  • 5
  • 19
  • In the DockerFile I added VOLUME ["/var/www/html"] USER www-data I still have in the Docker-compose file: volumes: - ./index.php:/var/www/html/index.php in the container /var/www/html/index.php has still user/group: root/root and not www-data:www-data. That is my problem – Jean-Pierre Mena Aug 07 '21 at 09:52
  • I solved the problem by using Docker On Windows with Window Subsystem for Linux (WSL). I add an Ubuntu on my windows. the Ubuntu has the same uid than the docker container – Jean-Pierre Mena Dec 23 '21 at 12:31