Skip to content

Instantly share code, notes, and snippets.

@aaabramov
Last active September 29, 2022 11:46
Show Gist options
  • Save aaabramov/654d81b088f8b857610cfdf0b801b832 to your computer and use it in GitHub Desktop.
Save aaabramov/654d81b088f8b857610cfdf0b801b832 to your computer and use it in GitHub Desktop.
NestJS Docker packaging
# Building layer
FROM node:16-alpine as development
# Optional NPM automation (auth) token build argument
# ARG NPM_TOKEN
# Optionally authenticate NPM registry
# RUN npm set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
WORKDIR /app
# Copy configuration files
COPY tsconfig*.json ./
COPY package*.json ./
# Install dependencies from package-lock.json, see https://docs.npmjs.com/cli/v7/commands/npm-ci
RUN npm ci
# Copy application sources (.ts, .tsx, js)
COPY src/ src/
# Build application (produces dist/ folder)
RUN npm run build
# Runtime (production) layer
FROM node:16-alpine as production
# Optional NPM automation (auth) token build argument
# ARG NPM_TOKEN
# Optionally authenticate NPM registry
# RUN npm set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
WORKDIR /app
# Copy dependencies files
COPY package*.json ./
# Install runtime dependecies (without dev/test dependecies)
RUN npm ci --omit=dev
# Copy production build
COPY --from=development /app/dist/ ./dist/
# Expose application port
EXPOSE 3000
# Start application
CMD [ "node", "dist/main.js" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment