gpt4 book ai didi

node.js - Docker - "Error: EACCES: permission denied, mkdir '/project/node_modules/.cache/@babel'”

转载 作者:搜寻专家 更新时间:2023-11-01 00:03:38 26 4
gpt4 key购买 nike

运行 yarn docker-build 工作正常,但是当 yarn docker-upyarn docker-dev 弹出错误RUN yarn 被调用。 Nginx 启动正常,但 yarn 无法进入项目目录中的 mkdir。

包.json

...
"docker-build": "docker-compose build",
"docker-dev": "cross-env NGINX_HOST=localhost NGINX_PORT=3000 PORT=3000 docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --no-deps",
"docker-up": "cross-env NGINX_HOST=localhost NGINX_PORT=80 PORT=8080 docker-compose -f docker-compose.yml -f docker-compose.prod.yml up --no-deps -d",
"docker-down": "docker-compose down"
...

docker 文件

FROM mhart/alpine-node:8

# Install required dependencies (Alpine Linux packages)
RUN apk update && \
apk add --no-cache \
sudo \
g++ \
gcc \
git \
libev-dev \
libevent-dev \
libuv-dev \
make \
openssl-dev \
perl \
python

# Add user and make it sudoer
ARG uid=1000
ARG user=username
RUN set -x ; \
addgroup -g $uid -S $user ; \
adduser -u $uid -D -S -G $user $user \
&& exit 0 ; exit 1
RUN echo $user' ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Install (global) Yarn packages/dependencies
RUN yarn global add node-gyp
RUN git clone --recursive https://github.com/sass/node-sass.git \
&& cd node-sass \
&& yarn \
&& node scripts/build -f

# Make project directory with permissions
RUN mkdir /project

# Switch to project directory
WORKDIR /project

# Copy required stuff
COPY . .

# Give owner rights to the current user
RUN chown -Rh $user:$user /project

# Install (local) Yarn packages and build
RUN yarn

USER $user

错误

app_1    | [2] Error: EACCES: permission denied, mkdir '/project/node_modules/.cache/@babel'
app_1 | [2] at Object.fs.mkdirSync (fs.js:885:18)
app_1 | [2] at sync (/project/node_modules/mkdirp/index.js:71:13)
app_1 | [2] at sync (/project/node_modules/mkdirp/index.js:77:24)
app_1 | [2] at save (/project/node_modules/@babel/register/lib/cache.js:50:20)
app_1 | [2] at _combinedTickCallback (internal/process/next_tick.js:132:7)
app_1 | [2] at process._tickCallback (internal/process/next_tick.js:181:9)
app_1 | [2] at Function.Module.runMain (module.js:696:11)
app_1 | [2] at startup (bootstrap_node.js:204:16)
app_1 | [2] at bootstrap_node.js:625:3

我的仓库可以在这里找到 https://github.com/cozy-nyc/cozy-nyc

最佳答案

我在 npm 上遇到了同样的问题。我使用以下方法修复了它:

RUN npm config set unsafe-perm true

另一种方法是在安装命令中指定它:

npm install -g --unsafe-perm thePackage

您可以在此处找到它的文档:https://docs.npmjs.com/misc/config#unsafe-perm

关于node.js - Docker - "Error: EACCES: permission denied, mkdir '/project/node_modules/.cache/@babel'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55926705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com