Skip to content

Instantly share code, notes, and snippets.

@vnphanquang
Last active October 18, 2025 08:34
Show Gist options
  • Select an option

  • Save vnphanquang/913e7afd5c9dba03fa685cc62bdba4a0 to your computer and use it in GitHub Desktop.

Select an option

Save vnphanquang/913e7afd5c9dba03fa685cc62bdba4a0 to your computer and use it in GitHub Desktop.
Sveltekit - Node - Minimal Dockerfile
name: my-app-stack
services:
app:
image: me/app
pull_policy: build
build:
context: .
dockerfile: ./dockerfile
tags:
- me/app:latest
environment:
- PORT=${PORT:-3000}
# add other services like DB, search, cache, etc. as needed
# Assuming using SvelteKit, Node adapter, and PNPM
# This multi-stage build instruction will:
# - optimize for smallest possible final image
# - leverage Docker cache for faster rebuilds
# docker buildx build --tag me/app .
# docker run --name my-app --publish 3000:3000 me/app
# base image from node-alpine, if your use case
# is complex you may need to use other tag
# you should also specify a version instead of `lts`
# for more predictability
FROM node:lts-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY ./package.json /app/package.json
FROM base AS deps-runtime
COPY ./pnpm-lock.yaml /app/pnpm-lock.yaml
COPY ./pnpm-workspace.yaml /app/pnpm-workspace.yaml
WORKDIR /app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
FROM base AS deps-build
COPY ./pnpm-lock.yaml /app/pnpm-lock.yaml
COPY ./pnpm-workspace.yaml /app/pnpm-workspace.yaml
WORKDIR /app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
FROM base AS builder
COPY . /app
COPY --from=deps-build /app/node_modules /app/node_modules
WORKDIR /app
RUN pnpm build
FROM base AS runner
COPY --from=deps-runtime /app/node_modules /app/node_modules
COPY --from=builder /app/build /app/build
WORKDIR /app
ENV PORT=3000
EXPOSE ${PORT}
CMD ["node", "build"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment