Skip to content

Instantly share code, notes, and snippets.

@lopezjurip
Last active May 28, 2020
Embed
What would you like to do?
A great Dockerfile for Node.js with Typescript and Yarn (multi-step build) and NPM Token for private modules
##
# First stage: prepare image
FROM node:12-alpine AS base
ARG NPM_TOKEN
ARG WORKDIR=/usr/src/app
WORKDIR ${WORKDIR}
# Install container build dependencies
RUN apk --no-cache add g++ ca-certificates lz4-dev musl-dev openssl-dev \
make python gcc zlib-dev libc-dev bsd-compat-headers py-setuptools git bash
# Install npm build dependencies
COPY package.json yarn.lock ./
RUN echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
RUN yarn install --frozen-lockfile
##
# Second stage: build app
FROM base AS build
ARG WORKDIR=/usr/src/app
WORKDIR ${WORKDIR}
# Build
COPY . ./
ENV NODE_ENV=production
RUN yarn build
##
# Third stage: run app
FROM base AS release
ARG WORKDIR=/usr/src/app
WORKDIR ${WORKDIR}
# Get "compiled" files
COPY --from=build ${WORKDIR} ./
EXPOSE 4000
ENV NODE_ENV=production
CMD [ "yarn", "start" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment