Last active
December 5, 2020 17:35
-
-
Save Hwan-seok/016d2cc2e8acd491ee2bdffe764d4008 to your computer and use it in GitHub Desktop.
Nodejs dockerfile best practice when using build(typescript/webpack)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author. Hwanseok Kang, [email protected] | |
FROM node:14.15.1-alpine3.12 AS build | |
RUN apk update && apk add curl bash | |
RUN curl -sfL https://gobinaries.com/tj/node-prune | bash -s -- -b /usr/local/bin | |
COPY package*.json /build/ | |
WORKDIR /build | |
RUN npm ci | |
ARG NODE_ENV | |
ENV NODE_ENV ${NODE_ENV} | |
COPY . /build | |
RUN npm run build | |
RUN npm prune --production && \ | |
rm -rf node_modules/rxjs/src/ \ | |
node_modules/rxjs/bundles/ \ | |
node_modules/rxjs/_esm5/ \ | |
node_modules/rxjs/_esm2015/ \ | |
node_modules/swagger-ui-dist/*.map | |
RUN /usr/local/bin/node-prune | |
FROM gcr.io/distroless/nodejs:14 | |
WORKDIR /app | |
ARG NODE_ENV | |
ENV NODE_ENV ${NODE_ENV} | |
COPY --from=build /build/node_modules /app/node_modules | |
COPY --from=build /build/dist /app/dist | |
EXPOSE 4000 | |
CMD [ "./dist/main.js" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment