Home > Blockchain >  Why I got Permission denied inside Docker container after npx create?
Why I got Permission denied inside Docker container after npx create?

Time:05-01

This is what I have done in the first place

docker run --name=nodesetup -it --mount type=bind,source="$(pwd)",target=/usr/src/app -w /usr/src/app 
node bash  

Mysql2 works fine

npm i mysql2

when I go for

npx create-react-app test-client
sh: 1: create-react-app: Permission denied

I am bind mounted root@83d263a01dc7:/usr/src/app/test-app#.

How to solve this?

CodePudding user response:

It's an issue with permissions on the host directory that you map. What exactly the issue is, I can't figure out. The container runs as root, so it should have access.

But if you run your container with the UID and GID of your user on the host by adding -u $(id -u):$(id -g) as an option, it works. Like this

docker run --name=nodesetup -it --mount type=bind,source="$(pwd)",target=/usr/src/app -w /usr/src/app -u $(id -u):$(id -g) node bash

This also has the advantage that the files created on the host are owned by you, making it easier to edit them, etc.

  • Related