# Docker (/docs/starter/docker)

Create `apps/web/.env.local` first. Start the development image with:

```sh
pnpm docker:dev
```

It runs `docker-compose.yml` by name (Starter v0.27.0 or newer), so a `compose.yaml` from [`deploy`](#production-with-docker-compose) never takes its place. Build a production image and run it with:

```sh
pnpm docker:build
pnpm docker:start
```

<Tabs items={['Next.js', 'TanStack Start', 'React + Vite']} groupId="framework" persist>
  <Tab value="Next.js">
    The image runs the Next.js standalone output as an unprivileged user.
  </Tab>
  <Tab value="TanStack Start">
    The image runs the self-contained Nitro server bundle as an unprivileged user, with no `node_modules`.
  </Tab>
  <Tab value="React + Vite">
    The image is the frontend only; the API has its own (see [below](#a-frontend-and-its-api)).
  </Tab>
</Tabs>

Ensure the configured database and provider hosts are reachable from the container.

## A frontend and its API [#a-frontend-and-its-api]

A project with a [separate API](../cli/frontend-and-api.mdx) has two production images:

| Image | Runs |
| --- | --- |
| `Dockerfile` | The frontend, on `node:22-alpine`: `node server.mjs` serves the static build on port 3000 and forwards the contract's `GET /api/health`, `/api/ready`, and `/api/session`, and the endpoints of the modules you chose, to `API_URL`, the API's address. With Better Auth, it also answers `/api/auth/*` itself. |
| `apps/api/Dockerfile` | The API, on port 3001: Node with Hono, or `python:3.12-slim` with uv with FastAPI, which installs only the dependency groups of your modules. Both include the migrator. |

The frontend server forwards no other path, and a module's endpoints only when the project has that module, such as the billing routes and Stripe's webhook with `--payments stripe`. When you add an endpoint to the contract, add it to `apiRoutes` in `apps/web/server.mjs`, or set `VITE_API_URL` so the browser calls the API directly.

Vite compiles the `VITE_*` variables into the build, so pass them as build arguments. `API_URL` is read when the server starts:

```sh
docker build \
  --build-arg VITE_SUPABASE_URL=https://<project>.supabase.co \
  --build-arg VITE_SUPABASE_PUBLISHABLE_KEY=sb_publishable_... \
  -t my-app-web .
docker build -f apps/api/Dockerfile -t my-app-api .
```

`pnpm docker:dev` builds and runs both with `docker-compose.yml`: the frontend with `apps/web/.env.local` and `API_URL` set to the API service, and the API with `apps/api/.env.local` and `TRUSTED_PROXY_HOPS=1`, since only the frontend's server reaches it. The frontend's `VITE_*` values are build arguments, since `.env` files stay out of the image: Compose reads them from the shell or a `.env` file next to `docker-compose.yml`, or run `docker compose -f docker-compose.yml --env-file apps/web/.env.local up --build`. Projects from Starter v0.24.1 and earlier pass none; add them under the frontend's `build.args`.

## Without a website [#without-a-website]

A project [without a website](../cli/without-a-website.mdx) has one image, the API's, `apps/api/Dockerfile`, and no `docker:build` or `docker:start`. Create `apps/api/.env.local` first: `pnpm docker:dev` builds the API's image and runs it with `docker-compose.yml`, publishing port 3001. Build and run the production image from the repository root with:

```sh
docker build -f apps/api/Dockerfile -t my-app-api .
docker run --rm -p 3001:3001 --env-file apps/api/.env.local my-app-api
```

The image runs the API as an unprivileged user, and contains the migrator.

## Production with Docker Compose [#production-with-docker-compose]

`docker-compose.yml` is for development. For a server of your own, [`pnpm clubedge deploy`](../cli/deploy/docker.mdx) with `--deploy docker` (CLI 0.42.0 or newer) writes a `compose.yaml` that runs the app's image behind [Caddy](https://caddyserver.com), which serves your domain over HTTPS, and `.github/workflows/release-images.yml`, which publishes the images to GitHub's container registry with each release. With a frontend and its API, it runs both, the API on the Compose network behind the frontend. Without a website, it runs the API's image, which Caddy serves (CLI 0.44.0 or newer).

Compose prefers `compose.yaml` to `docker-compose.yml`, so `pnpm docker:dev` names its file: `docker compose -f docker-compose.yml up --build` (Starter v0.27.0 or newer). In older projects, run that command instead of `pnpm docker:dev` once `compose.yaml` exists.

## The migrator [#the-migrator]

The image also contains the production migrator, which applies every package's migrations with only `DATABASE_URL`:

```sh
docker run --rm --env DATABASE_URL="postgresql://..." <image> node /app/migrate.mjs
```

Run it before a new version starts serving; it skips migrations that are already applied. [Deploy](./deploy/index.mdx) shows how each platform runs it.

With a separate API, the migrator is in the API's image, at the same path, with Hono and with FastAPI: run `node /app/migrate.mjs` from the API image, with a website or without one. The frontend image has none.
