Refactor example in best practices
This commit is contained in:
parent
ebc9c19382
commit
647fbaa404
|
@ -214,7 +214,6 @@ If you want to achieve an even smaller image size than the `-alpine`, you can om
|
|||
```Dockerfile
|
||||
ARG ALPINE_VERSION=3.16
|
||||
|
||||
|
||||
FROM node:18-alpine${ALPINE_VERSION} AS builder
|
||||
WORKDIR /build-stage
|
||||
COPY package*.json ./
|
||||
|
@ -223,19 +222,20 @@ RUN npm ci
|
|||
COPY . ./
|
||||
RUN npm run build
|
||||
|
||||
|
||||
FROM alpine:${ALPINE_VERSION}
|
||||
RUN apk add --no-cache libstdc++ dumb-init
|
||||
RUN addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/sh -D node
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
# Add required binaries
|
||||
RUN apk add --no-cache libstdc++ dumb-init \
|
||||
&& addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/sh -D node \
|
||||
&& chown node:node ./
|
||||
COPY --from=builder /usr/local/bin/node /usr/local/bin/
|
||||
COPY --from=builder /usr/local/bin/docker-entrypoint.sh /usr/local/bin/
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
WORKDIR /usr/src/app
|
||||
RUN chown node:node ./
|
||||
# Update the following COPY lines based on your codebase
|
||||
COPY --chown=node:node --from=builder /build-stage/node_modules ./node_modules
|
||||
COPY --chown=node:node --from=builder /build-stage/dist ./dist
|
||||
USER node
|
||||
# Update the following COPY lines based on your codebase
|
||||
COPY --from=builder /build-stage/node_modules ./node_modules
|
||||
COPY --from=builder /build-stage/dist ./dist
|
||||
# Run with dumb-init to not start node with PID=1, since Node.js was not designed to run as PID 1
|
||||
CMD ["dumb-init", "node", "dist/index.js"]
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue