0

HELLO I have the following folders structure

main

|- .docker-compose.yml
|- backend/
   |- micro-hr/
      |-.dockerfile
   |- rabbitmq

my docker compose:

 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

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

my entrypoint.sh:

#!/bin/bash

npm config set cache /usr/src/api/.npm-cache --global

cd /usr/src/api

npm install
npm run start:dev

i got this error on docker-compose up --build:

micro-hr              | > [email protected] 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! }

and:

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

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/",
3
  • Does your npm run start:dev script try to create /usr/local/etc? Commented Sep 7, 2020 at 22:20
  • is this: "start:dev": "ts-node-dev --inspect --respawn --transpile-only --ignore-watch node_modules -r tsconfig-paths/register src/index.ts", Commented Sep 7, 2020 at 22:21
  • @Narigo i edit the question Commented Sep 7, 2020 at 22:25

1 Answer 1

3

I think the problem is running npm install as root.

Try

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

instead of

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

Edit:

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.

Sign up to request clarification or add additional context in comments.

7 Comments

with this i got error on run npm install : > npm link ../rabbitmq/ npm ERR! code EACCES npm ERR! syscall symlink npm ERR! path /usr/src/rabbitmq npm ERR! dest /usr/local/lib/node_modules/rabbitmq
maybe with i got install from my main package and not permission on my rabbitmq
from what I realized my server on src / api ran normally, but it is not allowed to install on my rabbitmq modules
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! }
i tried it and it seemed to work normal until i go to my entry point and call npm install again then i have permission error
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.