aldikhan13

Simple Dockerfile Nodejs Configuration

May 15th, 2022 (edited)
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ############### RECOMMENDED DOCKER IMAGE VERSION ###############
  2. # <node version>-buster (debian 10) -> latest version
  3. # <node version>-stretch (debian 9) -> stable version
  4. # <node version>-alpine3.15 (alpine) -> small size version
  5. ################################################################
  6.  
  7. ######################
  8. # START STAGE 1
  9. ######################
  10. FROM node:14.19.1-buster as start # change node version with same your app use
  11. USER ${USER}
  12. ENV NODE_OPTIONS=--max_old_space_size=32768
  13. ADD ./package.*json ./
  14. ADD . ./
  15.  
  16. #######################
  17. # UPGRADE STAGE 2
  18. #######################
  19. FROM start as upgrade
  20. COPY --from=start . ./
  21. RUN apt-get autoremove \ # this command only for debian image version, change command if you use alpine linux image version
  22.   && apt-get autoclean \
  23.   && apt-get update \
  24.   && apt-get upgrade -y \
  25.   && apt-get install build-essential -y
  26.  
  27. #######################
  28. # FINAL STAGE 3
  29. #######################
  30. FROM upgrade as final
  31. COPY --from=upgrade . ./
  32. RUN rm -rf node_modules \
  33.   && npm cache clean -f \
  34.   && npm config delete proxy \
  35.   && npm config delete https-proxy \
  36.   && npm config delete proxy -g \
  37.   && npm config delete https-proxy -g \
  38.   && npm config set proxy null \
  39.   && npm config set https-proxy null \
  40.   && npm config set fetch-retries 15 \
  41.   && npm config set fetch-retry-factor 30 \
  42.   && npm config set fetch-retry-mintimeout 6000000 \
  43.   && npm config set fetch-retry-maxtimeout 12000000 \
  44.   && npm config set fetch-timeout 30000000 \
  45.   && npm config set prefer-offline true \
  46.   && npm config set unsafe-perm true \
  47.   && npm config set strict-ssl false \
  48.   && npm config set audit false \
  49.   && npm i -g --unsafe-perm \
  50.   && npm i node-gyp -g \
  51.   && npm i @xpack-dev-tools/windows-build-tools@latest -g \
  52.   && npm i pm2 -g \ # remove this if you not run your app with pm2
  53.   && npm i --loglevel verbose --no-audit \
  54.   && npm run build # change with your command app
  55. EXPOSE 3000 # change with your port app
  56. CMD npm run prod # change with your command app
Add Comment
Please, Sign In to add comment