Skip to content

Instantly share code, notes, and snippets.

@firebuggirl
Last active May 10, 2019 20:06
Show Gist options
  • Save firebuggirl/bfc64f2f1c6ab742f75dca87ca2ec26c to your computer and use it in GitHub Desktop.
Save firebuggirl/bfc64f2f1c6ab742f75dca87ca2ec26c to your computer and use it in GitHub Desktop.

Revisions

  1. firebuggirl revised this gist May 10, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion multi-stage-node-dockerfile-with-tini
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    FROM node:10-slim as prod
    # slim does not work w/tini
    # FROM node:10-slim as prod
    FROM node:10.15-alpine as prod

    ENV NODE_ENV=production

  2. firebuggirl created this gist May 8, 2019.
    46 changes: 46 additions & 0 deletions multi-stage-node-dockerfile-with-tini
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    FROM node:10-slim as prod

    ENV NODE_ENV=production

    EXPOSE 3000

    RUN apk add --no-cache tini

    WORKDIR WORKDIR /app

    COPY package*.json ./

    RUN npm install --only=production && npm cache clean --force

    COPY . .

    # ..use this in prod if want to prevent images from building as a result of failed tests
    # RUN npm test

    ENTRYPOINT ["/sbin/tini", "--"]

    CMD ["node", "./bin/www"]

    FROM prod as dev
    ENV NODE_ENV=development
    RUN npm install --only=development
    CMD ["../node_modules/nodemon/bin/nodemon.js", "./bin/www", "--inspect=0.0.0.0:9229"]

    FROM dev as test
    ENV NODE_ENV=development
    CMD ["npm", "test"]



    # Build + run prod:
    # docker build -t multistage --target prod . && docker run --init -p 3000:3000 multistage

    # Build + run dev:
    # docker build -t multistage:dev --target dev . && docker run --init -p 3000:3000 multistage:dev

    # need the tini `--init` process for `ctrl + c`..stopping container


    # Build + run test:
    # docker build -t multistage:test --target test . && docker run --init multistage:test