Add an example of a smaller alpine image without npm/yarn
This commit is contained in:
parent
209f981bb8
commit
9025d87163
|
@ -204,3 +204,42 @@ FROM node:alpine as app
|
|||
## Copy built node modules and binaries without including the toolchain
|
||||
COPY --from=builder node_modules .
|
||||
```
|
||||
|
||||
|
||||
## Smaller images without npm/yarn
|
||||
|
||||
If you want to achieve an even smaller image size than the `-alpine`, you can omit the npm/yarn like this:
|
||||
|
||||
```Dockerfile
|
||||
FROM node:18-alpine3.16 AS builder
|
||||
WORKDIR /build-stage
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Copy the the files you need
|
||||
COPY . ./
|
||||
|
||||
RUN npm run build
|
||||
|
||||
|
||||
# Make sure the alpine version is the same as in the build stage
|
||||
FROM alpine:3.16
|
||||
RUN apk add --no-cache libstdc++
|
||||
RUN apk add --no-cache dumb-init
|
||||
RUN addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/sh -D 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"]
|
||||
|
||||
# Update the following lines based on your codebase
|
||||
COPY --from=builder /build-stage/node_modules ./node_modules
|
||||
COPY --from=builder /build-stage/dist ./dist
|
||||
|
||||
RUN chown -R node:node ./
|
||||
USER node
|
||||
# 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