Skip to content

Commit ebc9c19

Browse files
authored
Update example config in best practices
- add workdir - use chown on copy for smaller image - create a variable for alpine version instead of explaining in a comment
1 parent 0c3d9de commit ebc9c19

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

docs/BestPractices.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,29 @@ COPY --from=builder node_modules .
212212
If you want to achieve an even smaller image size than the `-alpine`, you can omit the npm/yarn like this:
213213

214214
```Dockerfile
215-
FROM node:18-alpine3.16 AS builder
215+
ARG ALPINE_VERSION=3.16
216+
217+
218+
FROM node:18-alpine${ALPINE_VERSION} AS builder
216219
WORKDIR /build-stage
217220
COPY package*.json ./
218221
RUN npm ci
219-
220222
# Copy the the files you need
221223
COPY . ./
222-
223224
RUN npm run build
224225

225226

226-
# Make sure the alpine version is the same as in the build stage
227-
FROM alpine:3.16
227+
FROM alpine:${ALPINE_VERSION}
228228
RUN apk add --no-cache libstdc++ dumb-init
229229
RUN addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/sh -D node
230-
231230
COPY --from=builder /usr/local/bin/node /usr/local/bin/
232231
COPY --from=builder /usr/local/bin/docker-entrypoint.sh /usr/local/bin/
233232
ENTRYPOINT ["docker-entrypoint.sh"]
234-
235-
# Update the following lines based on your codebase
236-
COPY --from=builder /build-stage/node_modules ./node_modules
237-
COPY --from=builder /build-stage/dist ./dist
238-
239-
RUN chown -R node:node ./
233+
WORKDIR /usr/src/app
234+
RUN chown node:node ./
235+
# Update the following COPY lines based on your codebase
236+
COPY --chown=node:node --from=builder /build-stage/node_modules ./node_modules
237+
COPY --chown=node:node --from=builder /build-stage/dist ./dist
240238
USER node
241239
# Run with dumb-init to not start node with PID=1, since Node.js was not designed to run as PID 1
242240
CMD ["dumb-init", "node", "dist/index.js"]

0 commit comments

Comments
 (0)