Skip to content

Instantly share code, notes, and snippets.

@Fxlr8
Created February 8, 2018 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fxlr8/d97b375dc7d2a8ec84865e0f903f3ae8 to your computer and use it in GitHub Desktop.
Save Fxlr8/d97b375dc7d2a8ec84865e0f903f3ae8 to your computer and use it in GitHub Desktop.
Ye perfect dockerfile for node.js app
FROM node:alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN npm install --quiet # quiet flag to reduce logged information
# copy node modules to be able to mount source code and keep node_modules maintained by container to avoid rebuild on source code updates
RUN mkdir -p /dist/node_modules
RUN cp -r node_modules/* /dist/node_modules/
ENV NODE_PATH /dist/node_modules
# default host variable for nginx-proxy and node
ENV API_ROOT_CLIENT=
# copy project directory to WORKDIR
COPY . ./
EXPOSE 7778 3051
# run as node user instead of root for security reasons
USER node
CMD [ "npm", "run", "dev" ]
# docker run -p 7778:7778 -p 3051:3051 --rm -t -i -v $PWD:/usr/src/app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment