Skip to content

Instantly share code, notes, and snippets.

@sidwood
Last active September 26, 2017 04:39
Show Gist options
  • Save sidwood/f0887e334441a40cdc14b0c2ed002e0e to your computer and use it in GitHub Desktop.
Save sidwood/f0887e334441a40cdc14b0c2ed002e0e to your computer and use it in GitHub Desktop.
Node.js dockerfile templates
FROM sidwood/nodejs-app
USER root
RUN apk add --no-cache tree &&\
npm i -g nodemon
ENV NODE_ENV=development NODE_PATH=./lib:./test
EXPOSE 5858
USER node
CMD ["nodemon", "index.js"]
FROM node:7.10-alpine
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY ./package.json /opt/app
RUN apk add --update --no-cache tini &&\
apk add --virtual .build-dependencies make gcc g++ python &&\
npm install --production &&\
npm cache clean --force &&\
apk del .build-dependencies
COPY . /opt/app
ENV NODE_ENV=production NODE_PATH=./lib
EXPOSE 3000
# RUN addgroup -S app && adduser -S -g app app
# USER app
USER node
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "index.js"]
@antony
Copy link

antony commented May 5, 2017

I'd question the yarn install vs copying deps, but I don't see a way around it because we only want production dependencies there. Unless there is a prune method?

@antony
Copy link

antony commented May 5, 2017

btw everything else seems reasonable.

@antony
Copy link

antony commented May 5, 2017

yarnpkg/yarn#696

You could run prune as part of CI, outside the docker build, then copy the deps to the image rather than reinstall - then you wouldn't have to have all the build dependencies (as we don't have native modules).

@sidwood
Copy link
Author

sidwood commented May 5, 2017

Not sure I understand the aversion to installing dependencies in the container. As you say, it's required when building native components. What I'm trying to illustrate here is how we can install all the tools required to build native modules without keeping those tools around and bloating our docker image size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment