Skip to content

Instantly share code, notes, and snippets.

@lucius-feng
Forked from omerxx/Dockerfile
Created December 25, 2020 02:00
Show Gist options
  • Select an option

  • Save lucius-feng/f1ab867f7ba1dff29b8b3096a05d5198 to your computer and use it in GitHub Desktop.

Select an option

Save lucius-feng/f1ab867f7ba1dff29b8b3096a05d5198 to your computer and use it in GitHub Desktop.
# uses Docker Multi-Stage Build
# https://docs.docker.com/v17.09/engine/userguide/eng-image/multistage-build/
# -- builder container
FROM node:9-alpine as builder
# download Yelp/dumb-init
RUN apk add --no-cache curl
RUN curl -sL https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 -o /sbin/dumb-init \
&& chmod +x /sbin/dumb-init
WORKDIR /opt/app
# only run `yarn install` when package.json changed, otherwise use cache
COPY package.json /opt/app/
# install all dependencies in packages.json, including devDependencies
RUN yarn install
# copy the code before a babel build
COPY . /opt/app/
RUN yarn run -s build
# -- runtime container
FROM node:9-alpine
WORKDIR /opt/app
COPY --from=builder /sbin/dumb-init /sbin/dumb-init
# only run `yarn install` when package.json changed, otherwise use cache
COPY --from=builder /opt/app/package.json .
# do not install devDependencies, only "dependencies" from package.json
RUN yarn install --production
# copy the compiled code from builder
COPY --from=builder /opt/app/dist dist/
CMD [""]
ENTRYPOINT [ "/sbin/dumb-init", "/usr/local/bin/node", "dist/index.js" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment