Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EBUSY: resource busy or locked in Docker when trying to do npm install

Tags:

node.js

docker

I keep getting this error when I am trying to install an npm package.

Volumes in docker-compose.yml is set as follows:

volumes:
  - "./backend/packages/package.json:/home/node/package.json:delegated"
  - "./backend/packages/package-lock.json:/home/node/package-lock.json:delegated"
  - "./backend/:/home/node/app/"
  - /home/node/node_modules/

I want to run installs from inside the container it keeps giving me the following:

npm WARN saveError EBUSY: resource busy or locked, rename '/home/node/package.json.2756152664' -> '/home/node/package.json'
npm WARN saveError EBUSY: resource busy or locked, rename '/home/node/package-lock.json.2814803686' -> '/home/node/package-lock.json'
like image 373
yaserso Avatar asked Mar 21 '19 07:03

yaserso


People also ask

How do I stop NPM installing every time docker?

To avoid the npm install phase on every docker build just copy those lines and change the ^/opt/app^ to the location your app lives inside the container. That works.


Video Answer


2 Answers

Looks like npm uses mv to update the package files, but individually mounted files won't let this happen (just tried on a generic file, same symptom).

A solution using a mounted folder and links works for me, as described here: Locked package.json files in Docker container using docker-compose

like image 154
Will59 Avatar answered Nov 15 '22 06:11

Will59


I experienced the same issue when trying to do an npm install of a package inside a docker container. Instead of copying binding/mounting individual files from src folder, i mounted/bound the entire directory. The solution that worked for me was:

  1. Persist the node_modules volume and bind the entire directory
  2. Clear the cache
  3. Install through docker.

Here is the view of my docker-compose:

version: '3.1'
services:
  windaid:
  image: windaid
  build: ../WindAid-Website
  ports:
   - "3001:8000"
  volumes:
   - /myapp/node_modules #Persist after npm install from Dockerfile
   - ../WindAid-Website:/myapp #Binding entire directory

environment:
  - NODE_ENV=development
  - GATSBY_WEBPACK_PUBLICPATH=/

and here is a view of my Dockerfile:

FROM node:12.14.0-slim
RUN apt update && apt upgrade -y && \
    apt install gcc g++ make python git libc6-dev build-essential libpng-dev \
    libjpeg-dev libvips-dev libvips musl-dev node-gyp pngquant webp -y
 RUN yarn global add gatsby-cli
# The port gatsby runs on
EXPOSE 8000
WORKDIR /myapp
COPY ./package.json /myapp
COPY ./yarn.lock /myapp
RUN yarn install && yarn cache clean
RUN npm cache clean --force
CMD ["gatsby", "develop", "-H", "0.0.0.0" ]
like image 41
Rishfilet Avatar answered Nov 15 '22 07:11

Rishfilet