Skip to content

Commit 647fbaa

Browse files
authored
Refactor example in best practices
1 parent ebc9c19 commit 647fbaa

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/BestPractices.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ If you want to achieve an even smaller image size than the `-alpine`, you can om
214214
```Dockerfile
215215
ARG ALPINE_VERSION=3.16
216216

217-
218217
FROM node:18-alpine${ALPINE_VERSION} AS builder
219218
WORKDIR /build-stage
220219
COPY package*.json ./
@@ -223,19 +222,20 @@ RUN npm ci
223222
COPY . ./
224223
RUN npm run build
225224

226-
227225
FROM alpine:${ALPINE_VERSION}
228-
RUN apk add --no-cache libstdc++ dumb-init
229-
RUN addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/sh -D node
226+
# Create app directory
227+
WORKDIR /usr/src/app
228+
# Add required binaries
229+
RUN apk add --no-cache libstdc++ dumb-init \
230+
&& addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/sh -D node \
231+
&& chown node:node ./
230232
COPY --from=builder /usr/local/bin/node /usr/local/bin/
231233
COPY --from=builder /usr/local/bin/docker-entrypoint.sh /usr/local/bin/
232234
ENTRYPOINT ["docker-entrypoint.sh"]
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
238235
USER node
236+
# Update the following COPY lines based on your codebase
237+
COPY --from=builder /build-stage/node_modules ./node_modules
238+
COPY --from=builder /build-stage/dist ./dist
239239
# Run with dumb-init to not start node with PID=1, since Node.js was not designed to run as PID 1
240240
CMD ["dumb-init", "node", "dist/index.js"]
241241
```

0 commit comments

Comments
 (0)