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 .
212212If 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
216219WORKDIR /build-stage
217220COPY package*.json ./
218221RUN npm ci
219-
220222# Copy the the files you need
221223COPY . ./
222-
223224RUN 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}
228228RUN apk add --no-cache libstdc++ dumb-init
229229RUN addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/sh -D node
230-
231230COPY --from=builder /usr/local/bin/node /usr/local/bin/
232231COPY --from=builder /usr/local/bin/docker-entrypoint.sh /usr/local/bin/
233232ENTRYPOINT ["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
240238USER node
241239# Run with dumb-init to not start node with PID=1, since Node.js was not designed to run as PID 1
242240CMD ["dumb-init" , "node" , "dist/index.js" ]
You can’t perform that action at this time.
0 commit comments