File tree Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -212,31 +212,29 @@ COPY --from=builder node_modules .
212
212
If you want to achieve an even smaller image size than the ` -alpine ` , you can omit the npm/yarn like this:
213
213
214
214
``` 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
216
219
WORKDIR /build-stage
217
220
COPY package*.json ./
218
221
RUN npm ci
219
-
220
222
# Copy the the files you need
221
223
COPY . ./
222
-
223
224
RUN npm run build
224
225
225
226
226
- # Make sure the alpine version is the same as in the build stage
227
- FROM alpine:3.16
227
+ FROM alpine:${ALPINE_VERSION}
228
228
RUN apk add --no-cache libstdc++ dumb-init
229
229
RUN addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/sh -D node
230
-
231
230
COPY --from=builder /usr/local/bin/node /usr/local/bin/
232
231
COPY --from=builder /usr/local/bin/docker-entrypoint.sh /usr/local/bin/
233
232
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
240
238
USER node
241
239
# Run with dumb-init to not start node with PID=1, since Node.js was not designed to run as PID 1
242
240
CMD ["dumb-init" , "node" , "dist/index.js" ]
You can’t perform that action at this time.
0 commit comments