Skip to content
Snippets Groups Projects
Dockerfile 1.13 KiB
Newer Older
# ---- Base Node ----
FROM node:16.17.0-alpine AS base
# install node
RUN apk add --no-cache nodejs-current npm tini yarn
# set working directory
WORKDIR /code
# Set tini as entrypoint
ENTRYPOINT ["/sbin/tini", "--"]
# copy project file
COPY package.json package-lock.json yarn.lock next.config.js ./

#
# ---- Dependencies ----
FROM base AS dependencies
# install git
RUN apk add --no-cache git
# install node packages
RUN npm install --only=production
# copy production node_modules aside
RUN cp -R node_modules prod_node_modules
# install ALL node_modules, including 'devDependencies'
RUN npm install

#
# ---- Builder ----
FROM base AS builder
# copy production node_modules
COPY --from=dependencies /code/node_modules ./node_modules
# copy app sources
COPY . .
# build app
RUN npm build

# ---- Release ----
FROM base AS release

# expose port and define CMD
EXPOSE 5000

# copy production node_modules
COPY --from=dependencies /code/prod_node_modules ./node_modules

# copy build files
COPY --from=builder /code/static ./static
COPY --from=builder /code/assets ./assets
COPY --from=builder /code/.next ./.next
CMD yarn run start -H 0.0.0.0 -p 5000