Docker
Learn how to deploy your supastarter application as a Docker container.
In this guide we are going to show you how to deploy your supastarter application as a Docker container, so you can deploy it to any platform or server that supports docker images.
Why deploy your SaaS as a Docker container?
Deploying your SaaS as a Docker container allows you to have complete control over your server environment. It ensures better privacy, contributes to cost savings if managed correctly, and offers you the flexibility to customize your server setup to suit your specific needs. It can also give your application a performance boost compared to hosting on a serverless platform like Vercel, as it removes cold starts.
Setup Nuxt app for docker deployment
Nuxt automatically builds a standalone output that can be run in a Docker container. No additional configuration is needed.
Setup docker configuration for the Nuxt app
Create a Dockerfile in the root of your Nuxt app (e.g. apps/saas/Dockerfile) with the following content:
FROM node:22-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
FROM base AS builder
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
RUN pnpm add -g turbo
COPY . .
RUN turbo prune saas --docker
FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
ENV CYPRESS_INSTALL_BINARY=0
RUN pnpm install
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
RUN pnpm turbo run build --filter=saas...
FROM base AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nuxt
USER nuxt
COPY --from=installer --chown=nuxt:nodejs /app/apps/saas/.output ./
USER nuxt
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
CMD ["node", "server/index.mjs"]In the root of the supastarter project, also add a .dockerignore file with the following content:
Dockerfile
.dockerignore
node_modules
**/node_modules
npm-debug.log
README.md
.nuxt
.output
.gitAnd that's all the changes necessary! Now you can build your app as a docker image and deploy it anywhere you can run docker images.
Running your app locally with Docker
If you have Docker installed on your local machine and want to run your Nuxt app there for testing the docker image, build the Dockerfile of the app you are deploying.
For example, for the SaaS app:
docker build -f apps/saas/Dockerfile . --no-cache -t supastarter-docker
docker run -p 3000:3000 supastarter-dockerTo fully use the application, you need to pass the necessary environment variables you have defined in your .env.local file to the container.
Now you can deploy your app to any server that supports docker images.