Dockerfile 881 B

12345678910111213141516171819202122232425262728293031323334
  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. # use production node environment by default
  4. ENV NODE_ENV=production
  5. # set working directory.
  6. WORKDIR /kutt
  7. # download dependencies while using Docker's caching
  8. RUN --mount=type=bind,source=package.json,target=package.json \
  9. --mount=type=bind,source=package-lock.json,target=package-lock.json \
  10. --mount=type=cache,target=/root/.npm \
  11. npm ci --omit=dev
  12. RUN mkdir -p /var/lib/kutt
  13. # copy the rest of source files into the image
  14. COPY . .
  15. # switch back to node 22 for running the app
  16. FROM node:22-alpine
  17. # set working directory.
  18. WORKDIR /kutt
  19. # copy built application from build phase
  20. COPY --from=build_image /kutt ./
  21. # expose the port that the app listens on
  22. EXPOSE 3000
  23. # intialize database and run the app
  24. CMD npm run migrate && npm start