Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

Docker permission issues with Yarn

I'm having the following issue when trying run my container:

psa-web    | Error: EACCES: permission denied, open '/root/.config/yarn'
psa-web    |     at Object.openSync (node:fs:495:3)
psa-web    |     at readFileSync (node:fs:396:35)
psa-web    |     at /opt/yarn-v1.22.5/lib/cli.js:101332:58
psa-web    |     at Array.map (<anonymous>)
psa-web    |     at parseRcPaths (/opt/yarn-v1.22.5/lib/cli.js:101330:78)
psa-web    |     at Object.findRc (/opt/yarn-v1.22.5/lib/cli.js:101344:10)
psa-web    |     at getRcConfigForCwd (/opt/yarn-v1.22.5/lib/cli.js:56916:74)
psa-web    |     at /opt/yarn-v1.22.5/lib/cli.js:92695:56
psa-web    |     at Generator.next (<anonymous>)
psa-web    |     at step (/opt/yarn-v1.22.5/lib/cli.js:310:30)
psa-web    | npm ERR! code 1
psa-web    | npm ERR! path /usr/src/app
psa-web    | npm ERR! command failed
psa-web    | npm ERR! command sh -c yarn install && next dev
psa-web    | 
psa-web    | npm ERR! A complete log of this run can be found in:
psa-web    | npm ERR!     /root/.npm/_logs/2021-01-29T09_01_06_202Z-debug.log
version: "3"

services:
  psa-web:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: psa-web
    restart: always
    volumes:
      - ./:/usr/src/app
      - /usr/src/app/node_modules
      - /usr/src/app/.next
    ports:
      - "${NEXT_PUBLIC_APP_PORT}:${NEXT_PUBLIC_APP_PORT}"

Here's my Dockerfile:

FROM node:15.5.0-alpine3.10

RUN apk add --update --no-cache 
    python 
    make 
    g++

WORKDIR /usr/src/app

# install and cache app dependencies
COPY package.json /usr/src/app
COPY yarn.lock /usr/src/app

RUN yarn install --frozen-lockfile


EXPOSE 3003
CMD ["npm", "run", "dev"]

Here's also the package.json file, for better context. That's were I automatically run yarn install before starting my next application on dev, and the potential source of this error.

package.json

"scripts": {
    "dev": "yarn install && next dev",
    "build": "next build",
    "start": "yarn install && next start",
    "lint": "eslint .",
    "update:shared-deps": "yarn upgrade --scope @project-stock-alarm --latest",
    "lint:fix": "eslint . --fix"
  },

Any ideas of what I'm doing wrong?

If I do a sudo yarn install and a sudo chown -R root it solves the issue, but this is not best practice.

question from:https://stackoverflow.com/questions/65951517/docker-permission-issues-with-yarn

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...