Dockerfile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # if you're doing anything beyond your local machine, please pin this to a specific version at https://hub.docker.com/_/node/
  2. FROM node:10
  3. RUN mkdir -p /opt/app
  4. # set our node environment, either development or production
  5. # defaults to production, compose overrides this to development on build and run
  6. ARG NODE_ENV=production
  7. ENV NODE_ENV $NODE_ENV
  8. # default to port 80 for node, and 9229 and 9230 (tests) for debug
  9. ARG PORT=80
  10. ENV PORT $PORT
  11. EXPOSE $PORT 9229 9230
  12. # you'll likely want the latest npm, reguardless of node version, for speed and fixes
  13. RUN npm i npm@latest -g
  14. # install dependencies first, in a different location for easier app bind mounting for local development
  15. WORKDIR /opt
  16. COPY package.json package-lock.json* ./
  17. RUN npm install && npm cache clean --force
  18. ENV PATH /opt/node_modules/.bin:$PATH
  19. # check every 30s to ensure this service returns HTTP 200
  20. HEALTHCHECK --interval=30s CMD node healthcheck.js
  21. # copy in our source code last, as it changes the most
  22. WORKDIR /opt/app
  23. COPY . /opt/app
  24. # if you want to use npm start instead, then use `docker run --init in production`
  25. # so that signals are passed properly. Note the code in index.js is needed to catch Docker signals
  26. # using node here is still more graceful stopping then npm with --init afaik
  27. # I still can't come up with a good production way to run with npm and graceful shutdown
  28. CMD [ "node", "index.js" ]