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'
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.
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
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:
node_modules
volume and bind the entire directoryHere 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" ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With