wtsang11 / TechExplore

MIT License
0 stars 0 forks source link

Sect 2: Docker Imager and Containers #165

Open wtsang11 opened 3 years ago

wtsang11 commented 3 years ago

Layer Concept and Implication to Optimize a DockerFile

FROM node:12

WORKDIR /app

COPY package.json /app

RUN npm install

COPY . /app

EXPOSE 80

CMD ["node", "server.js"]

Note: npm install will run only package.json file is changed. Most of the time, it does not change. Therefore, DO NOT put the COPY command ahead of RUN npm install. The reason COPY command will cause the RUN npm install to run again because COPY will cause package.json file apparently changed in the new layer.