Skip to content

Instantly share code, notes, and snippets.

@nwesterhausen
Created February 24, 2022 00:23
Show Gist options
  • Save nwesterhausen/5820044f1777b5faa67e146912b3811e to your computer and use it in GitHub Desktop.
Save nwesterhausen/5820044f1777b5faa67e146912b3811e to your computer and use it in GitHub Desktop.
Dockerize nodejs, pnpm using distroless
# Ignore All
*
# Allow Some
!bin/www
!db/**
!public/**
!routes/**
!util/**
!views/**
!app.js
!package.json
!pnpm-lock.yaml
# "build" app with full node container
FROM registry.hub.docker.com/library/node:16 AS build-env
# Default working directory
WORKDIR /app
# Download and install PNPM
RUN curl -f https://get.pnpm.io/v6.16.js | \
node - add --global pnpm
# pnpm fetch does require only lockfile
COPY pnpm-lock.yaml ./
RUN pnpm fetch --prod
# Bundle app source (use a .dockerignore file to only move what you want)
ADD . ./
# Install using fetched data from lockfile
RUN pnpm install -r --offline --prod
# Move "built" app into distroless node container
FROM gcr.io/distroless/nodejs:16
COPY --from=build-env /app /app
WORKDIR /app
# Include ENV and VOLUME stuff here.
CMD ["./bin/www"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment