Last active
June 3, 2019 07:16
-
-
Save sidwood/f45aa8a6be395b09720ea1290e83eadc to your computer and use it in GitHub Desktop.
Node.js Dockerfile example
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:10.16-alpine | |
WORKDIR /opt/app | |
ARG NODE_ENV=production | |
ARG NODE_PATH=./lib | |
ARG NPM_TOKEN | |
ARG REVISION | |
ARG VERSION | |
ENV NODE_ENV=$NODE_ENV \ | |
NODE_PATH=$NODE_PATH \ | |
PATH=/opt/node_modules/.bin:$PATH \ | |
PORT=3000 \ | |
REVISION=$REVISION \ | |
VERSION=$VERSION | |
COPY --chown=node:node ./package.json ./package-lock.json /opt/ | |
RUN apk add --update --no-cache tini \ | |
&& apk add --no-cache curl \ | |
&& apk add --no-cache --virtual .build-dependencies make gcc g++ python \ | |
&& cd /opt \ | |
&& echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc \ | |
&& npm config ls \ | |
&& npm i -g [email protected] \ | |
&& npm ci --silent --progress=false \ | |
&& npm cache clean --force \ | |
&& chown -R node:node /opt/app \ | |
&& chown -R node:node /opt/node_modules \ | |
&& apk del .build-dependencies \ | |
&& rm -rf yarn* \ | |
&& rm .npmrc | |
COPY --chown=node:node . /opt/app | |
EXPOSE 3000 9229 9230 | |
# Simple http endpoint reports 200 OK on database, transport and cacher connections | |
# Also useful for exposing $REVISION and $VERSION as well as broker NODE_ID | |
HEALTHCHECK --interval=5s --timeout=3s --start-period=10s --retries=3 \ | |
CMD curl -fs http://0.0.0.0:3000/heartbeat || exit 1 | |
USER node | |
ENTRYPOINT ["/sbin/tini", "--"] | |
CMD ["node", "-r", "make-promises-safe", "index.js"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment