-
Notifications
You must be signed in to change notification settings - Fork 24
/
Dockerfile
56 lines (42 loc) · 1.48 KB
/
Dockerfile
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
48
49
50
51
52
53
54
55
56
# environment variables: image
ARG NODE_VERSION=16.13.1
ARG ALPINE_VERSION=alpine3.14
# multi-stage: base (build)
FROM node:$NODE_VERSION-$ALPINE_VERSION AS base
# create directory where the application will be built
WORKDIR /app
# copy over the dependency manifests, both the package.json
# and the package-lock.json are copied over
COPY package*.json ./
# installs packages and their dependencies
RUN npm ci
# copy over the code base
COPY . .
# create the bundle of the application
RUN npm run build
# multi-stage: production (runtime)
FROM node:$NODE_VERSION-$ALPINE_VERSION AS runtime
# environment variables: user & configuration
ARG user=amplication
ARG group=${user}
ARG uid=1001
ARG gid=$uid
ENV NODE_ENV=production
# create directory where the application will be built
WORKDIR /app
# add the user
RUN addgroup --system --gid ${gid} ${group}
RUN adduser --system --uid ${uid} ${user}
# copy and change ownership of directories and files
COPY --from=base --chown=${user}:${group} /app/package.json ./
COPY --from=base --chown=${user}:${group} /app/node_modules ./node_modules
COPY --from=base --chown=${user}:${group} /app/public ./public
COPY --from=base --chown=${user}:${group} /app/.next ./.next
COPY --from=base --chown=${user}:${group} /app/next.config.js ./
# set user to the created non-privileged user
USER ${user}
# expose a specific port on the docker container
ENV PORT=3000
EXPOSE ${PORT}
# start the server using the previously build application
CMD ["npx", "next", "start"]