Dockerfile 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ## Base ########################################################################
  2. # Use a larger node image to do the build for native deps (e.g., gcc, python)
  3. FROM node:lts as base
  4. # Reduce npm log spam and colour during install within Docker
  5. ENV NPM_CONFIG_LOGLEVEL=warn
  6. ENV NPM_CONFIG_COLOR=false
  7. # We'll run the app as the `node` user, so put it in their home directory
  8. WORKDIR /home/node/app
  9. # Copy the source code over
  10. COPY --chown=node:node . /home/node/app/
  11. ## Development #################################################################
  12. # Define a development target that installs devDeps and runs in dev mode
  13. FROM base as development
  14. WORKDIR /home/node/app
  15. # Install (not ci) with dependencies, and for Linux vs. Linux Musl (which we use for -alpine)
  16. RUN npm install
  17. # Switch to the node user vs. root
  18. USER node
  19. # Expose port 3000
  20. EXPOSE 3000
  21. # Start the app in debug mode so we can attach the debugger
  22. CMD ["npm", "start"]
  23. ## Production ##################################################################
  24. # Also define a production target which doesn't use devDeps
  25. FROM base as production
  26. WORKDIR /home/node/app
  27. COPY --chown=node:node --from=development /home/node/app/node_modules /home/node/app/node_modules
  28. # Build the Docusaurus app
  29. RUN npm run build
  30. ## Deploy ######################################################################
  31. # Use a stable nginx image
  32. FROM nginx:stable-alpine as deploy
  33. WORKDIR /home/node/app
  34. # Copy what we've installed/built from production
  35. # COPY --chown=node:node --from=production /home/node/app/build /usr/share/nginx/html/
  36. COPY --from=production /home/node/app/build /usr/share/nginx/html/