Last active
September 26, 2017 04:39
-
-
Save sidwood/f0887e334441a40cdc14b0c2ed002e0e to your computer and use it in GitHub Desktop.
Node.js dockerfile templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
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).
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
btw everything else seems reasonable.