Skip to content
Snippets Groups Projects
Dockerfile 1.57 KiB
Newer Older
#---------- DEVELOPMENT ----------
FROM node:16-alpine AS development
# we do not want to run under the root user
USER node

# install node_modules outside app root in container so local development won't run into a problem of bind-mounting over it with local source code
COPY --chown=node:node ["package.json", "package-lock.json", "./"]
RUN npm install
# ensures that exactly these executables (from the node_modules folder) are used instead of any other executables which might also be installed on the system inside the Docker image
ENV PATH=/usr/src/node_modules/.bin:$PATH

WORKDIR /usr/src/app
COPY --chown=node:node prisma/schema.prisma ./prisma/
Martin Korec's avatar
Martin Korec committed
RUN npx prisma generate

CMD ["npm", "run", "start:dev"]


#---------- PRODUCTION ----------
FROM node:16-alpine AS production

# we do not want to run under the root user
USER node

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src

COPY --chown=node:node --from=development /usr/src/package.json ./
COPY --chown=node:node --from=development /usr/src/package-lock.json ./
# install only 'dependencies' and not 'devDependencies'
RUN npm install --omit=dev
# ensures that exactly these executables (from the node_modules folder) are used instead of any other executables which might also be installed on the system inside the Docker image
ENV PATH=/usr/src/node_modules/.bin:$PATH

WORKDIR /usr/src/app

COPY --chown=node:node prisma/schema.prisma ./prisma/
RUN npx prisma generate

COPY --chown=node:node --from=development /usr/src/app/dist ./dist

CMD ["npm", "run", "start:prod"]