I have seen a few tutorials about docker but then I saw this on a web page
FROM node:10-alpine
RUN mkdir -p /home/node/node_modules && chown -R node:node /home/node
WORKDIR /home/node
COPY package*.json ./
USER node
RUN npm install
COPY --chown=node:node . .
EXPOSE 8080
CMD [ "node", "app.js" ]
So why I need this and whats chown -R
RUN mkdir -p /home/node/node_modules && chown -R node:node /home/node
>Solution :
Your mkdir command creates a sub-folder within the node folder, and the chown -R command changes ownership of the folder to the user node recursively (the folder and all it’s contents).
This is required because the node app uses the node user to create files and folders in the /home/node directory. This is important from a cybersecurity perspective, especially if you don’t want the app running as an admin or root account.