DEV Community

Discussion on: Containerize React app with Docker for Production

Collapse
 
jhonatangiraldo profile image
Jhonatan Giraldo

Hey, great article. A couple of questions:

  1. Why do we need to add node_modules to the path? ENV PATH /app/node_modules/.bin:$PATH
  2. Why do you copy explicitly the package.json if anyway you will copy everything from the root? COPY ./package.json /app/ # <-- redundant? COPY . /app
  3. What is the advantage of running nginx in the foreground instead of daemon? CMD ["nginx", "-g", "daemon off;"]
Collapse
 
bjkeller profile image
Ben Keller

The answer to 2 is that Docker builds images in layers with rebuilds being triggered for all layers after a change has been detected. Since installing dependencies takes time and happens less frequently than code updates, it is better to isolate that step to avoid having dependencies installed every time you tweak your code.