运行时出现权限错误
ng build --prod --env=prod
在Docker容器中。我认为我正在处理所有各种npm config设置,并且安装很好。但是当我运行时,出现此错误:
EACCES: permission denied, unlink '/home/node/rbs/dist/0.0b84f6ea259174c0238a.chunk.js'
Error: EACCES: permission denied, unlink '/home/node/rbs/dist/0.0b84f6ea259174c0238a.chunk.js'
at Object.fs.unlinkSync (fs.js:1061:18)
at rimrafSync (/home/node/rbs/node_modules/fs-extra/lib/remove/rimraf.js:254:15)
at options.readdirSync.forEach.f (/home/node/rbs/node_modules/fs-extra/lib/remove/rimraf.js:291:39)
at Array.forEach (<anonymous>)
at rmkidsSync (/home/node/rbs/node_modules/fs-extra/lib/remove/rimraf.js:291:26)
at rmdirSync (/home/node/rbs/node_modules/fs-extra/lib/remove/rimraf.js:281:7)
at Object.rimrafSync [as removeSync] (/home/node/rbs/node_modules/fs-extra/lib/remove/rimraf.js:252:7)
at Class.run (/home/node/rbs/node_modules/@angular/cli/tasks/build.js:29:16)
at Class.run (/home/node/rbs/node_modules/@angular/cli/commands/build.js:250:40)
at resolve (/home/node/rbs/node_modules/@angular/cli/ember-cli/lib/models/command.js:261:20)
at new Promise (<anonymous>)
at Class.validateAndRun (/home/node/rbs/node_modules/@angular/cli/ember-cli/lib/models/command.js:240:12)
at Promise.resolve.then.then (/home/node/rbs/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:140:24)
at <anonymous>
这是我的docker配置:
FROM node:8.11.3-alpine as build
RUN apk add --update python make
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=/home/node/.npm-global/bin:$PATH
USER node
RUN mkdir /home/node/rbs && \
npm install -g -f @angular/cli@1.7.4
##
## The section below is split to save cache time
#
# dependencies build only (only includes files for npm install)
#
RUN npm -g config set user root
ADD ./package.json /home/node/rbs
ADD ./package-lock.json /home/node/rbs
RUN cd /home/node/rbs && \
npm install
#
# Source build with ng (requires all sources)
#
ADD . /home/node/rbs
RUN cd /home/node/rbs && \
ng build --prod --env=prod
#
# Runtime; we will vend resources via nginx
#
FROM nginx:1.13.8-alpine
COPY --from=build /home/node/rbs/dist /usr/share/nginx/html
ADD ./container-files .
答案 0 :(得分:0)
docker build
默认情况下会将整个当前目录作为其“上下文”目录,然后,当您的Dockerfile说ADD . /home/node/rbs
时,该目录将添加到映像中。但是,如果您的工作树已经有一个dist
目录,那么该目录也会被复制到其中,并且ng build
命令必须与先前存在的内容抗衡。
您可以通过运行来验证是否是问题所在
rm -rf dist
docker build .
一个更永久的解决方法是创建一个.dockerignore file,告诉Docker在构建时不要包含dist
目录。
echo /dist >> .dockerignore
docker build .
如果dist
目录已经存在,则ADD
命令将其添加到owned by root:
所有新文件和目录的UID和GID为0,除非可选的--chown标志指定[其他] ....
由于您已告诉ng build
以备用NODE
用户身份运行,因此将无法删除拥有根目录的dist
树,这会导致您看到错误