docker和docker-compose节点api:npm ERR!代码EACCES [英] docker and docker-compose node api: npm ERR! code EACCES
问题描述
HELLO我具有以下文件夹结构
HELLO I have the following folders structure
main
|- .docker-compose.yml
|- backend/
|- micro-hr/
|-.dockerfile
|- rabbitmq
我的码头工人组成:
micro-hr:
build:
context: .
dockerfile: backend/micro-hr/Dockerfile
entrypoint: /usr/src/api/.docker/entrypoint.sh
container_name: micro-hr
environment:
- CHOKIDAR_USEPOLLING=true
ports:
- 3001:3000
我的dockerfile:
my dockerfile:
FROM node:lts-alpine
#create app directory
#xx
RUN mkdir /usr/src
RUN apk add --no-cache bash git
RUN touch /usr/src/.bashrc | echo "PS1='\w\$ '" >> /usr/src/.bashrc
#copy files
COPY backend/micro-hr/ormconfig.ts backend/micro-hr/.env backend/micro-hr/package.json backend/micro-hr/yarn.* /usr/src/api/
COPY backend/rabbitmq/package.json /usr/src/rabbitmq/
#install modules lib modules
RUN cd /usr/src/api/ && npm install
#copy other files
COPY backend/micro-hr/ /usr/src/api/
COPY backend/rabbitmq /usr/src/rabbitmq
RUN chown -R node:node /usr/src/api
RUN chown -R node:node /usr/src/rabbitmq
WORKDIR /usr/src/api
#set work dir
USER node
我的入口点.sh:
#!/bin/bash
npm config set cache /usr/src/api/.npm-cache --global
cd /usr/src/api
npm install
npm run start:dev
我在docker-compose up --build:
i got this error on docker-compose up --build:
micro-hr | > micro-hr@1.0.0 postinstall /usr/src/api
micro-hr | > npm link ../rabbitmq/
micro-hr |
micro-hr | npm ERR! code EACCES
micro-hr | npm ERR! syscall symlink
micro-hr | npm ERR! path /usr/src/rabbitmq
micro-hr | npm ERR! dest /usr/local/lib/node_modules/rabbitmq
micro-hr | npm ERR! errno -13
micro-hr | npm ERR! Error: EACCES: permission denied, symlink '/usr/src/rabbitmq' -> '/usr/local/lib/node_modules/rabbitmq'
micro-hr | npm ERR! [Error: EACCES: permission denied, symlink '/usr/src/rabbitmq' -> '/usr/local/lib/node_modules/rabbitmq'] {
micro-hr | npm ERR! errno: -13,
micro-hr | npm ERR! code: 'EACCES',
micro-hr | npm ERR! syscall: 'symlink',
micro-hr | npm ERR! path: '/usr/src/rabbitmq',
micro-hr | npm ERR! dest: '/usr/local/lib/node_modules/rabbitmq'
micro-hr | npm ERR! }
和:
micro-hr | npm WARN checkPermissions缺少对/ usr / src / api / node_modules / has-symbols micro-hr的写访问
| npm
WARN checkPermissions缺少对
的写访问权/usr/src/api/node_modules/highlight.js
micro-hr | npm WARN checkPermissions Missing write access to /usr/src/api/node_modules/has-symbols micro-hr | npm WARN checkPermissions Missing write access to /usr/src/api/node_modules/highlight.js
我知道这是一个权限问题,但我不知道如何解决。
的问题是在安装我的npm链接模块时:
I know it's a problem with permission but I can't figure out how to fix it. the problem is when installing my npm link modules:
"postinstall": "npm link ../rabbitmq/",
"postupdate": "npm link ../rabbitmq/",
推荐答案
我认为问题是作为root用户运行 npm install
。
I think the problem is running npm install
as root.
尝试
USER node
RUN cd /usr/src/api/ && npm install
#copy other files
COPY --chown node:node backend/micro-hr/ /usr/src/api/
COPY --chown node:node backend/rabbitmq /usr/src/rabbitmq
WORKDIR /usr/src/api
而不是
RUN cd /usr/src/api/ && npm install
#copy other files
COPY backend/micro-hr/ /usr/src/api/
COPY backend/rabbitmq /usr/src/rabbitmq
RUN chown -R node:node /usr/src/api
RUN chown -R node:node /usr/src/rabbitmq
WORKDIR /usr/src/api
#set work dir
USER node
基于这篇文章我会将之前的建议修改为:
Based on this article I would modify my previous suggestion to:
USER node
RUN mkdir ~/.npm-global && npm config set prefix '~/.npm-global' && \
export PATH=~/.npm-global/bin:$PATH && \
cd /usr/src/api/ && npm install
#copy other files
ENV PATH="~/.npm-global/bin:${PATH}"
COPY --chown node:node backend/micro-hr/ /usr/src/api/
COPY --chown node:node backend/rabbitmq /usr/src/rabbitmq
WORKDIR /usr/src/api
编辑:
我认为 entrypoint.sh
可能会导致新问题:
I think this line in entrypoint.sh
may cause the new problem:
npm config set cache /usr/src/api/.npm-cache --global
尝试将其删除或注释并重建图像。
Try removing or commenting it out and rebuilding the image.
这篇关于docker和docker-compose节点api:npm ERR!代码EACCES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!