Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ---- 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