juliushaertl / nextcloud-docker-dev

Nextcloud development environment using docker-compose
GNU Affero General Public License v3.0
137 stars 72 forks source link

permission denied: webpack inside of the container #170

Closed vdtoorn closed 1 year ago

vdtoorn commented 1 year ago

I've installed the nextcloud-docker-dev container according to the tutorials, on Windows. I've started building an app, and of course I want to create javascript, and it looks like the Makefile is the ticket for that. Unfortunately, from the Docker terminal, it is not possible to finish the make command. It does start but as soon as it starts to use webpack via the npm run build command, it stops with 'permission denied' I also noticed all of the app files have owner/group 1000, which is not present in passwd. I don't know if this is a bug, but I don't know where to ask otherwise.

juliushaertl commented 1 year ago

I don't have a windows setup myself but on Linux/macOS the mounted source code is mounted owned by root in the containers, so there it works fine. Can you tell which user the docker terminal uses?

vdtoorn commented 1 year ago

Docker uses root in the terminal. I'm wondering if I did something wrong while installing the skeleton app.

juliushaertl commented 1 year ago

Can you send me the output of the following commands from within the docker terminal?

ls -l /var/www/html
ls -l /var/www/html/apps-extra
ls -l /var/www/html/apps-extra/myapp

The tutorial suggests to move the file on the windows explorer. I'm unsure if that makes any difference there with WSL2.

vdtoorn commented 1 year ago

root@b6ec1097e473:/var/www/html# ls -l /var/www/html/ total 2020 drwxr-xr-x 45 1000 1000 4096 Feb 27 15:53 3rdparty -rw-r--r-- 1 1000 1000 19327 Feb 27 15:53 AUTHORS -rw-r--r-- 1 1000 1000 111 Feb 27 15:53 CHANGELOG.md -rw-r--r-- 1 1000 1000 938 Feb 27 15:53 CODE_OF_CONDUCT.md -rw-r--r-- 1 1000 1000 34520 Feb 27 15:53 COPYING -rw-r--r-- 1 1000 1000 607 Feb 27 15:53 COPYING-README -rw-r--r-- 1 1000 1000 1201 Feb 27 15:53 DESIGN.md -rw-r--r-- 1 1000 1000 383 Feb 27 15:53 Makefile -rw-r--r-- 1 1000 1000 7847 Feb 27 15:53 README.md -rw-r--r-- 1 1000 1000 1207 Feb 27 15:53 SECURITY.md drwxr-xr-x 30 1000 1000 4096 Feb 27 15:53 apps drwxr-xr-x 8 1000 1000 4096 Feb 28 11:51 apps-extra drwxr-xr-x 2 1000 1000 4096 Feb 27 15:53 apps-shared drwxr-xr-x 4 1000 1000 4096 Mar 20 14:23 apps-writable -rwxr-xr-x 1 1000 1000 329 Feb 27 15:53 autotest-checkers.sh -rwxr-xr-x 1 1000 1000 8396 Feb 27 15:53 autotest-external.sh -rwxr-xr-x 1 1000 1000 173 Feb 27 15:53 autotest-js.sh -rwxr-xr-x 1 1000 1000 14104 Feb 27 15:53 autotest.sh -rw-r--r-- 1 1000 1000 293 Feb 27 15:53 babel.config.js drwxr-xr-x 6 1000 1000 4096 Feb 27 15:53 build -rw-r--r-- 1 1000 1000 1234 Feb 27 15:53 composer.json -rw-r--r-- 1 1000 1000 3140 Feb 27 15:53 composer.lock drwxr-xr-x 2 1000 1000 4096 Feb 28 17:35 config -rw-r--r-- 1 1000 1000 4095 Feb 27 15:53 console.php drwxr-xr-x 2 1000 1000 4096 Feb 27 15:53 contribute drwxr-xr-x 25 1000 1000 4096 Feb 27 15:53 core -rw-r--r-- 1 1000 1000 6317 Feb 27 15:53 cron.php drwxr-xr-x 5 1000 1000 4096 Feb 27 15:53 cypress -rw-r--r-- 1 1000 1000 3132 Feb 27 15:53 cypress.config.ts drwxrwx--- 6 1000 1000 4096 Feb 27 15:56 data drwxr-xr-x 2 1000 1000 12288 Feb 27 15:53 dist -rw-r--r-- 1 1000 1000 156 Feb 27 15:53 index.html -rw-r--r-- 1 1000 1000 3456 Feb 27 15:53 index.php -rw-r--r-- 1 1000 1000 1998 Mar 23 10:23 installing.html -rw-r--r-- 1 1000 1000 1716 Feb 27 15:53 jest.config.js drwxr-xr-x 6 1000 1000 4096 Feb 27 15:53 lib -rwxr-xr-x 1 1000 1000 283 Feb 27 15:53 occ drwxr-xr-x 2 1000 1000 4096 Feb 27 15:53 ocm-provider drwxr-xr-x 2 1000 1000 4096 Feb 27 15:53 ocs drwxr-xr-x 2 1000 1000 4096 Feb 27 15:53 ocs-provider -rw-r--r-- 1 1000 1000 1730304 Feb 27 15:53 package-lock.json -rw-r--r-- 1 1000 1000 6071 Feb 27 15:53 package.json -rw-r--r-- 1 1000 1000 722 Feb 27 15:53 psalm-ocp.xml -rw-r--r-- 1 1000 1000 5068 Feb 27 15:53 psalm.xml -rw-r--r-- 1 1000 1000 3139 Feb 27 15:53 public.php -rw-r--r-- 1 1000 1000 5549 Feb 27 15:53 remote.php drwxr-xr-x 4 1000 1000 4096 Feb 27 15:53 resources -rw-r--r-- 1 1000 1000 26 Feb 27 15:53 robots.txt -rw-r--r-- 1 1000 1000 2452 Feb 27 15:53 status.php drwxr-xr-x 12 1000 1000 4096 Feb 27 15:53 tests drwxr-xr-x 3 1000 1000 4096 Feb 27 15:53 themes -rw-r--r-- 1 1000 1000 646 Feb 27 15:53 tsconfig.json drwxr-xr-x 4 1000 1000 4096 Feb 27 15:53 vendor-bin -rw-r--r-- 1 1000 1000 1710 Feb 27 15:53 version.php -rw-r--r-- 1 1000 1000 4718 Feb 27 15:53 webpack.common.js -rw-r--r-- 1 1000 1000 394 Feb 27 15:53 webpack.config.js -rw-r--r-- 1 1000 1000 5736 Feb 27 15:53 webpack.modules.js

root@b6ec1097e473:/var/www/html# ls -l /var/www/html/apps-extra total 24 drwxr-xr-x 12 1000 1000 4096 Feb 27 15:53 files_pdfviewer drwxr-xr-x 7 1000 1000 4096 Feb 27 15:54 hmr_enabler drwxr-xr-x 13 1000 1000 4096 Mar 23 13:41 my_app drwxr-xr-x 13 1000 1000 4096 Feb 27 15:54 profiler drwxr-xr-x 10 1000 1000 4096 Feb 27 15:53 recommendations drwxr-xr-x 14 1000 1000 4096 Feb 27 15:53 viewer

root@b6ec1097e473:/var/www/html# ls -l /var/www/html/apps-extra/my_app/ total 232 drwxr-xr-x 2 1000 1000 4096 Feb 28 11:51 LICENSES -rw-r--r-- 1 1000 1000 4824 Jan 1 1970 Makefile -rw-r--r-- 1 1000 1000 1849 Jan 1 1970 README.md drwxr-xr-x 2 1000 1000 4096 Feb 28 11:51 appinfo -rw-r--r-- 1 1000 1000 203 Jan 1 1970 babel.config.js -rw-r--r-- 1 1000 1000 1214 Mar 20 13:35 composer.json -rw-r--r-- 1 1000 1000 160201 Mar 23 09:12 composer.lock drwxr-xr-x 2 1000 1000 4096 Mar 22 09:40 img drwxr-xr-x 2 1000 1000 4096 Mar 23 12:00 js drwxr-xr-x 7 1000 1000 4096 Feb 28 11:51 lib -rw-r--r-- 1 1000 1000 1417 Mar 23 13:39 package.json -rw-r--r-- 1 1000 1000 1194 Jan 1 1970 psalm.xml drwxr-xr-x 2 1000 1000 4096 Feb 28 11:51 src -rw-r--r-- 1 1000 1000 193 Jan 1 1970 stylelint.config.js drwxr-xr-x 2 1000 1000 4096 Feb 28 11:51 templates drwxr-xr-x 4 1000 1000 4096 Feb 28 11:51 tests drwxr-xr-x 17 1000 1000 4096 Mar 23 09:12 vendor -rw-r--r-- 1 1000 1000 213 Jan 1 1970 webpack.config.js

I did perform a chown -R 1000:1000 /var/www/html to get everything on the same user again.

juliushaertl commented 1 year ago

Interesting they should be owned by root in the container at least this is how this ends up on Linux/macOS.

@szaimen Since you are using Windows, do you have any idea if there something we could do to make sure that the volumes mounted from windows would take the container user for their permissions?

szaimen commented 1 year ago

For that using docker volumes instead of bind-mounts would be the solution...

juliushaertl commented 1 year ago

Then it lacks the ability to edit them locally with your windows editor since it is about having a dev environment :/

juliushaertl commented 1 year ago

Though I don't really remember this being a problem when I tried the setup a year ago with windows

szaimen commented 1 year ago

I see. Maybe it needs a chown from inside the container then or something?

juliushaertl commented 1 year ago

https://github.com/docker/for-win/issues/12742 looks related

juliushaertl commented 1 year ago

Might be caused then by step 7 of https://cloud.nextcloud.com/s/iyNGp8ryWxc7Efa?dir=undefined&path=%2F1%20Setting%20up%20a%20development%20environment%2FTutorial%20for%20Windows&openfile=7087340 if being executed as the default user of Ubuntu through WSL2

Screenshot 2023-03-24 at 11 15 28

vdtoorn commented 1 year ago

Hi, I think you're right about some aspects: I have indeed followed that tutorial step by step, and apparently wsl2 creates a user with uid 1000 that corresponds to your windows user. It opens up all kinds of connections between user 1000 and the windows user, for instance the possibility to open the files in windows explorer and for instance the possibility to open the windows VS code from the linux command line. Inside the container windows 1000 is not known.

So after changing ownershop of the source (and html) tree, and running npm install, I do get the possibility to run npm run build, which creates js files in the proper place. Unfortunately now I can't edit the files in VS code anymore, because they are owned by 'root'...

I'm also getting many errors from npm that it can't find @nextcloud references. Are there any environment variables that it would expect to see change when going into the docker container?

I'm a bit stuck here, I don't feel like having to chowning the files all the time, but also I have the feeling I'm missing something in terms of setup.

juliushaertl commented 1 year ago

One option might be to run web pack and potential build steps in the WSL terminal instead of the docker one, that way you could keep the user (1000) and still be able to update files.

vdtoorn commented 1 year ago

I have done this and it works perfectly! Also, npm build watch works in this scenario. Thank you all very much for your effort!

One more thing to do is to find out how to switch off browser caching, I'll report back if I find something useful.

This may be a good addition to the Windows installation guide!