I’m using Docker to develop a Node.js project with npm. I’ve set up a Dockerfile to keep my machine clean by mounting the code to a Docker volume and running Node.js and npm within the container.
Initially, I just installed the dependencies locally. But I ran into issues with dependencies. I solved them by installing dependencies globally, but I’m not happy with this solution. Are there better ways to handle this? And is it okay to install dependencies globally for Node.js projects in Docker containers? Any advice would be appreciated!
FROM debian:bullseye
ARG userUID=1000
RUN useradd -m -u $userUID node_user
RUN DEBIAN_FRONTEND=noninteractive apt update && apt install -y nodejs npm curl
RUN npm -g install n && n stable
WORKDIR /home/node_user/src
ADD package.json .
RUN chown -R 1000:1000 /home/node_user/src
RUN npm install -g
USER node_user
TheComputerCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.