-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile-new
47 lines (33 loc) · 1.06 KB
/
Dockerfile-new
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
# FROM Sid Palas via Twitter
# https://twitter.com/sidpalas/status/1634194026500096000?s=20
# In specific version for stability
FROM node:12-alpine AS base
# Specify working directory other than /
WORKDIR /usr/src/app
# Copy only files required to install
# dependencies (better layer caching)
COPY package*.json ./
FROM base AS dev
RUN node --version && npm --version
RUN --mount=type=cache,target=/usr/scr/app/.npm \
npm set cache /usr/src/app/.npm && \
npm install
COPY . .
CMD ["npm", "run", "dev"]
FROM base AS production
# Set NODE_ENV
ENV NODE_ENV production
# Install only production dependencies
# Use cache mount to speed up install of existing dependencies
RUN --mount=type=cahce,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm ci --only=production
# Use non-root user
# Use --chown on COPY commands to set file permissions
USER node
# Copy remaining source code AFTER installing dependencies.
# Again, copy only necessary files
COPY --chown=node:node ./src/ .
# Indicate expected port
EXPOSE 3000
CMD ["node", "index.js"]