Dockerfile 1007 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # use older node version for build since arm/v8 threw error when node 20 was used
  2. FROM node:18.19.1-alpine AS build_image
  3. # install additional tools needed if on arm64 / armv7
  4. RUN apk add --update python3 make g++\
  5. && rm -rf /var/cache/apk/*
  6. # use production node environment by default
  7. ENV NODE_ENV=production
  8. # set working directory.
  9. WORKDIR /kutt
  10. # download dependencies while using Docker's caching
  11. RUN --mount=type=bind,source=package.json,target=package.json \
  12. --mount=type=bind,source=package-lock.json,target=package-lock.json \
  13. --mount=type=cache,target=/root/.npm \
  14. npm ci --omit=dev
  15. RUN mkdir -p /var/lib/kutt
  16. # copy the rest of source files into the image
  17. COPY . .
  18. # switch back to node 22 for running the app
  19. FROM node:22-alpine
  20. # set working directory.
  21. WORKDIR /kutt
  22. # copy built application from build phase
  23. COPY --from=build_image /kutt ./
  24. # expose the port that the app listens on
  25. EXPOSE 3000
  26. # intialize database and run the app
  27. CMD npm run migrate && npm start