当我运行npm run development
时,我得到错误:
Creating api_node_run ... done
> dev
> npm run development
npm WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm WARN logfile error cleaning log files [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
npm WARN logfile errno: -13,
npm WARN logfile code: 'EACCES',
npm WARN logfile syscall: 'scandir',
npm WARN logfile path: '/root/.npm/_logs'
npm WARN logfile }
> development
> mix
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /root/.npm/_cacache/tmp
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 1000:33 "/root/.npm"
npm ERR! Log files were not written due to an error writing to the directory: /root/.npm/_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
npm notice
npm notice New major version of npm available! 8.19.4 -> 10.2.5
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.2.5
npm notice Run npm install -g [email protected] to update!
npm notice
字符串
我在docker-compose.yml
中定义了一个Docker Node容器:
node:
image: connectedplaces/api/node
build:
context: ./docker/node
dockerfile: Dockerfile
volumes:
- .:/var/www/html
型
Dockerfile是:
# Set base image.
FROM node:16.20
# Install git for faster package downloads.
RUN apt-get install -y git
RUN chown -R node:node /root/.npm
# Set the working directory to the project root.
WORKDIR /var/www/html
型
容器将成功启动,如果我检查权限:
docker-compose run --rm --entrypoint "" node ls -lart /root/.npm
型
输出为:
drwxr-xr-x 1 node node 4096 Sep 7 22:33 _logs
drwx------ 1 root root 4096 Sep 7 22:33 ..
drwxr-xr-x 1 node node 4096 Sep 7 22:33 .
型
我遵循了Node Docker can't run dev command的想法,但我仍然无法解决这个错误。我已经删除了本地镜像并重建了它,我已经在Dockerfile中碰撞了Node版本并重建了它,但似乎没有什么工作。
你知道下一步该怎么做吗?
2条答案
按热度按时间cxfofazt1#
在尝试了所有建议的解决方案后,唯一有效的方法是创建一个新的缓存目录,并在Dockerfile中将
npm_config_cache
设置为:字符串
这是由@ASHBRN-PHNX在Error "Your cache folder contains root-owned files, due to a bug in previous versions of npm" while "npx create-react-app example_app"中建议的。
kpbwa7wx2#
它应该通过使用“node”用户uid和gid作为构建参数来使事情变得更好,而不是“改变”所有的东西以使其适合。
字符串
和
型
比如
这样你就可以使用主机用户的uid和gid进行开发(在macos上通常是501,在Ubuntu 1000/1001上我想是的)。