Dockerfile
1 # syntax=docker/dockerfile:1 2 3 # Comments are provided throughout this file to help you get started. 4 # If you need more help, visit the Dockerfile reference guide at 5 # https://docs.docker.com/engine/reference/builder/ 6 7 ARG NODE_VERSION=19.5.0 8 9 FROM node:${NODE_VERSION}-alpine 10 11 # Use production node environment by default. 12 ENV NODE_ENV production 13 14 # Change working directory 15 WORKDIR /usr/src/app 16 17 # Download dependencies as a separate step to take advantage of Docker's caching. 18 # Leverage a cache mount to /root/.npm to speed up subsequent builds. 19 # Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into 20 # into this layer. 21 RUN --mount=type=bind,source=package.json,target=package.json \ 22 --mount=type=bind,source=package-lock.json,target=package-lock.json \ 23 --mount=type=cache,target=/root/.npm \ 24 npm ci --omit=dev 25 26 # Run the application as a non-root user. 27 USER node 28 29 # Copy the rest of the source files into the image. 30 COPY . . 31 32 # Expose the port that the application listens on. 33 EXPOSE 3001 34 35 # Run the application. 36 CMD npm run dev