This issue is happening due to changes in NodeJS starting with version 15. When no WORKDIR
is specified, npm install
is executed in the root directory of the container, which is resulting in this error. Executing the npm install
in a project directory of the container specified by WORKDIR
resolves the issue.
Use the following Dockerfile
:
# Specify a base image
FROM node:alpine
#Install some dependencies
WORKDIR /usr/app
COPY ./ /usr/app
RUN npm install
# Set up a default command
CMD [ "npm","start" ]