I want to create a new nextjs app in my current directory on the host, but without installing node etc. So I run a container like this
docker run --rm -it -v $(pwd):/app node:17.8.0 bash
whoami
shows that I'm root in the container. Then I run these commands in the container
cd /app
npx create-next-app@latest
and get this output
Need to install the following packages:
create-next-app@latest
Ok to proceed? (y) y
sh: 1: create-next-app: Permission denied
npm notice
npm notice New minor version of npm available! 8.5.5 -> 8.6.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.6.0
npm notice Run npm install -g [email protected] to update!
npm notice
I don't understand why I get permission denied, since I'm root.
It has something to do with the volume mapping of the host directory, because if I run the container without the volume mapping, the command works.
The permissions in the host directory look like this
drwxrwxr-x 2 hans hans 4096 Apr 9 10:35 .
drwxrwxr-x 11 hans hans 4096 Apr 9 10:21 ..
Why does it fail and how can I get it to work?
CodePudding user response:
My suggestion is to run the container right away with the correct UID/GID, so that you don't have to fix the permissions later on. This might also solve the initial problem.
docker run -u "$(id -u):$(id -g)" ...