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.
Related
I am new to Docker and I am trying to run a container following this tutorial and was running into some issues while using the --volume or -v as shown below:
docker run -v <absolute path to host directory>:<absolute path to container working directory> <image id>
So mine looks like this:
docker run -p 3000:3000 -v /usr/app/node_modules -v "$(pwd)":/usr/app 900a3497fc39
The error thrown is this:
npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /usr/app/package.json
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, open '/usr/app/package.json'
npm ERR! [Error: EACCES: permission denied, open '/usr/app/package.json'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/usr/app/package.json'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-11-12T13_39_38_626Z-debug.log
I have built the image without any issues:
docker build -f Dockerfile.dev .
Sending build context to Docker daemon 23.55kB
Step 1/6 : FROM node
---> f1974cfde44f
Step 2/6 : WORKDIR /usr/app
---> Using cache
---> 120da5dd5fa4
Step 3/6 : COPY ./package.json ./
---> Using cache
---> 040ba41014c8
Step 4/6 : RUN npm install
---> Using cache
---> 96315e12e5d0
Step 5/6 : COPY . .
---> db93b8725037
Step 6/6 : CMD [ "npm", "run", "dev" ]
---> Running in 9c9d58318420
Removing intermediate container 9c9d58318420
---> 900a3497fc39
Successfully built 900a3497fc39
My Dockerfile.dev looks like this:
FROM node
WORKDIR /usr/app
COPY ./package.json ./
RUN npm install
COPY . .
CMD [ "npm", "run", "dev" ]
And the package.json looks like this:
{
"name": "vite-counter",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": {
"vue": "^3.0.0-beta.15"
},
"devDependencies": {
"vite": "^1.0.0-beta.3",
"#vue/compiler-sfc": "^3.0.0-beta.15"
}
}
From what I understand, I do not have sufficient permissions in the container to run this. This is exactly what I was following in the tutorial. What am I doing wrong and how do I fix this?
Trying to build my dockerfile, and getting a permission denied error.
The project is a nest.js server. Here is the dockerfile:
FROM node:12.13-alpine
WORKDIR /usr/src/app
COPY package.json .
RUN npm install <<< this fails
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
and the error (on npm install) is:
internal/fs/utils.js:220
throw err;
^
Error: EACCES: permission denied, open '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
at Object.openSync (fs.js:440:3)
at Object.readFileSync (fs.js:342:35)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:994:22)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11 {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
Any idea?
Solved. the solution was in 2 steps:
re-install docker.
changing owner to node, like this:
FROM node:10
RUN mkdir -p /home/node/app && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package.json .
USER node
RUN npm install
...
I am working on a Nest.js application and this is the Dockerfile that we have. When I run this I am getting an error on the npm run build step in docker.
This is the build task in package.json.
"build": "nest build"
sh: nest: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! atom-qbuilder-api#0.0.1 build: `nest build`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the atom-qbuilder-api#0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Dockerfile
# Build
FROM node:8-alpine as builder
COPY package.json /usr/src/atom/package.json
COPY package-lock.json /usr/src/atom/package-lock.json
WORKDIR /usr/src/atom
# Install dependencies
RUN npm install --production --loglevel warn
ARG APPLICATION
ARG BRANCH
ARG BUILD_NUMBER
ARG SHA
ENV NODE_ENV qa
ENV VERSION 1.0.0
## Copy app directory in container and set workdir
COPY . /usr/src/atom
# Build & Test Coverage
RUN set -x \
&& npm run build \
&& echo "{ \"status\": \"Ok\", \"result\": { \"version\": \"$VERSION\", \"branchName\": \"$BRANCH\", \"SHA\": \"$SHA\", \"buildDate\": \"$(date)\", \"buildNumber\": \"$BUILD_NUMBER\", \"environment\": \"$NODE_ENV\" } }" > build.json
# Release
FROM node:8-alpine
ENV PORT 3000
COPY --from=builder /usr/src/atom/node_modules /usr/src/atom/node_modules
COPY --from=builder /usr/src/atom/dist /usr/src/atom/dist
COPY --from=builder /usr/src/atom/package.json /usr/src/atom/package.json
COPY --from=builder /usr/src/atom/build.json /usr/src/atom/build.json
WORKDIR /usr/src/atom
EXPOSE $PORT
## Run supervisor as foreground process
CMD bash -c "npm run start:prod && /usr/bin/supervisord"
#nestjs/cli (where the nest command comes from) is by default in devDependencies. Unless you've modified your deps in package.json, running npm i --production will not install #nestjs/cli which will lead to the error you currently have. You can either use a multi-staged dockerfile or move #nestjs/cli to your dependencies instead of devDeps.
I have simple node.app, with this package.json:
{
"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "xxxxx",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.1",
"myuser-deploy": "git+ssh://git#github.com:myuser/deploy.git"
}
}
Normally when I run "npm i", it installs all dependencies, and also the one form the github. I have SSH that I previously setup with the github. All works fine so far.
Now I added Docker support for my application, like this
Dockerfile:
FROM node:carbon
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
docker-compose.yml:
version: "3"
services:
test-service:
build: .
image: test-service
container_name: test-service
working_dir: /usr/src/app
user: node
restart: always
ports:
- '3001:3000'
When I run docker-compose up, it gives me this error:
> npm ERR! Error while executing: npm ERR! /usr/bin/git ls-remote -h -t
> ssh://git#github.com/myuser/deploy.git npm ERR! npm ERR! Host key
> verification failed. npm ERR! fatal: Could not read from remote
> repository. npm ERR! npm ERR! Please make sure you have the correct
> access rights npm ERR! and the repository exists. npm ERR! npm ERR!
> exited with error code: 128
>
> npm ERR! A complete log of this run can be found in:
What can I do with the docker, so it uses my SSH keys?
I appreciate your help!
I have the following Dockerfile:
FROM node:slim
RUN mkdir -p /project
WORKDIR /project
# workdir is empty
RUN ls -a
COPY . /project
# workdir is full
RUN ls -a
# this command create node_modules folder on it own
RUN npm install
# I have node_modules folder with packages
RUN ls -a
RUN ls -d node_modules/*
Last outputs are:
Step 8/9 : RUN ls -a
---> Running in 90d8793f491a
.
..
.babelrc
.editorconfig
.eslintignore
.eslintrc.js
.git
.gitignore
.postcssrc.js
Dockerfile-dev
README.md
build
config
docker-compose.dev.yml
index.html
node_modules
package-lock.json
package.json
src
static
test
Removing intermediate container 90d8793f491a
---> b563d272b270
Step 9/9 : RUN ls -d node_modules/*
---> Running in a14bb4024e5e
node_modules/#babel
node_modules/#types
node_modules/abab
node_modules/abbrev
node_modules/accepts
node_modules/acorn
But when I look at the container's files from the following command:
docker-compose -f docker-compose.dev.yml run project ls
I have no node_modules folder (folder with dependencies) and my container cannot start because of it:
docker-compose -f docker-compose.dev.yml up
sh: 1: webpack-dev-server: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! project#1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the project#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-04-11T19_09_35_669Z-debug.log
The docker-compose is simple:
version: '3'
services:
project:
container_name: project
build:
context: .
dockerfile: Dockerfile-dev
command: npm run dev
volumes:
- .:/project
ports:
- 8080:8080
The questions are: why it happens? How to solve the problem?
why it happens?
https://github.com/moby/moby/issues/4361#issuecomment-167156818
How to solve the problem?
https://github.com/moby/moby/issues/4361#issuecomment-210231967