Last active
October 18, 2025 08:34
-
-
Save vnphanquang/913e7afd5c9dba03fa685cc62bdba4a0 to your computer and use it in GitHub Desktop.
Sveltekit - Node - Minimal Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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