pnp / docker-spfx

Docker images for working with SharePoint Framework
https://hub.docker.com/r/m365pnp/spfx
MIT License
116 stars 48 forks source link

spfx user issue when using WSL2, an Ubuntu host and Docker #61

Closed robertirelanddev closed 2 years ago

robertirelanddev commented 2 years ago

I am using a Windows 10 Pro host (10.0.19043) with WSL 2 and Windows Docker (Docker Desktop 4.3.0 (71786).

Running under WSL 2 is an instance of Ubuntu. I have two images within Docker waldekm/spfx:latest and waldekm/spfx:1.12.1

Within the Ubuntu instance running under WSL 2 I have created a folder in /home/rob/projects/sp-dev-demo and git cloned my SPfx project there.

I then start Windows Docker by using docker run -it --rm --name SPfx-Development-Demo -v $PWD:/usr/app/spfx -p 4321:4321 -p 35729:35729 waldekm/spfx:1.12.1

This starts the Docker Container image

If I run npm install to install the local dependencies I get the following error message

spfx@207b798a3966:/usr/app/spfx$ npm install npm WARN checkPermissions Missing write access to /usr/app/spfx npm ERR! code EACCES npm ERR! syscall access npm ERR! path /usr/app/spfx npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, access '/usr/app/spfx' npm ERR! [Error: EACCES: permission denied, access '/usr/app/spfx'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/usr/app/spfx' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in: npm ERR! /home/spfx/.npm/_logs/2021-12-09T12_11_30_775Z-debug.log

If I type whoami I get the response of spfx

If I try and create a file as the spfx user using touch file.txt I get permission denied.

If I try and edit the code with VS Code and save a file I also get permission denied errors.

If I list the files in the folder using ls -l I see the following

spfx@207b798a3966:/usr/app/spfx$ ls -l total 836 -rw-r--r-- 1 node node 2553 Dec 8 19:21 README.md drwxr-xr-x 2 node node 4096 Dec 8 19:21 config -rw-r--r-- 1 node node 407 Dec 8 19:21 gulpfile.js -rw-r--r-- 1 node node 823269 Dec 8 19:21 package-lock.json -rw-r--r-- 1 node node 956 Dec 8 19:21 package.json drwxr-xr-x 3 node node 4096 Dec 8 19:21 src drwxr-xr-x 2 node node 4096 Dec 8 19:21 teams -rw-r--r-- 1 node node 772 Dec 8 19:21 tsconfig.json -rw-r--r-- 1 node node 826 Dec 8 19:21 tslint.json

To me (and I'm no Linux expert) it looks like the spfx account created as part of the Docker container doesn't have permissions to write to my project files.

image

I also get permission denied issues if I try and use yo @microsoft/sharepoint to create a new project in a new project folder.

I have done some reading around this and I've seen a number of people talk about adding a shared drive to Docker. Unfortunately this isn't an option as that feature does not exist in the Windows version of Docker.

If I try the same from the Windows Host and connect to the same Docker container the SPfx user has the correct permissions to complete installing the local dependencies when I run NPM Install. Additionally @yo @microsoft/sharepoint works as you would expect it.

Any help greatly appreciated.

Best wishes, Rob Ireland

robertirelanddev commented 2 years ago

Turns out it was the permissions of my /home/rob/projects folder. Once I changed the permissions and started docker again everything was fine.

robertirelanddev commented 2 years ago

Resolved by changing the permissions within the Ubuntu instance running in WSL 2

waldekmastykarz commented 2 years ago

Thank you for sharing the solution and great to hear that you're unblocked 👍

shurick81 commented 2 years ago

Do you remember @robertirelanddev how exactly you gave the permissions?