Abstract


--build-arg

Allows us to pass dynamic values to Docker Engine for the building process. Not Environment Variable, that is set with ENV!

Great for frontend build which only needs inputs at container build stage, not when container is running

Docker Build Cache


Build app dependencies before app

For example, we can copy & build the package.json first. Since dependencies usually don’t really change. If we include the dependencies installation with the main application. We need to re-install the dependencies whenever there is a change to the application

FROM node:18-alpine3.15
WORKDIR /xy241
 
# Install dependencies first to take advantage of Docker's caching
COPY package.json .
RUN npm install 
 
COPY . .
EXPOSE 3000
CMD ["npm", "npm.js"]