# Docker Compose (/docs/cli/deploy/docker)

In a project with `--deploy docker` (the default), `pnpm clubedge deploy` prepares the project for a server of your own (CLI 0.42.0 or newer). It creates nothing anywhere else: it writes the files, then prints what to run on the server.

```sh
pnpm clubedge deploy             # writes compose.yaml, the Caddyfile, and the release workflow
pnpm clubedge deploy --dry-run   # what it would write
```

## What it writes [#what-it-writes]

Three files to commit:

- **`compose.yaml`** runs each app's image behind [Caddy](https://caddyserver.com), the only service that publishes ports (80, and 443 over TCP and UDP). Caddy serves `DOMAIN` over HTTPS, with certificates it obtains and renews by itself.
- **`Caddyfile`**: every request for `DOMAIN` goes to the public app.
- **`.github/workflows/release-images.yml`**: each published GitHub release builds every app's image and pushes it to GitHub's container registry ([below](#release-images)).

| Project | Services |
| --- | --- |
| Next.js or TanStack Start | `web`, from the root `Dockerfile` |
| A [frontend and its API](../frontend-and-api.mdx) | `web`, the frontend, which Caddy serves, and `api`, which stays on the Compose network behind the frontend's `/api` proxy |
| [Without a website](../without-a-website.mdx) (CLI 0.44.0 or newer) | `api`, from `apps/api/Dockerfile`, which Caddy serves |

Each service has an image, `${IMAGE_PREFIX:-<project>}-<service>:${TAG:-latest}`, and its build: `docker compose up -d` pulls the released images when `IMAGE_PREFIX` points at GitHub's registry, and `--build` builds them on the server. The public URL defaults to `https://$DOMAIN`: Next.js also gets it as a build argument, and Better Auth as `BETTER_AUTH_URL`, on a React + Vite frontend or in an API without a website. A [mobile app](../../starter/mobile-app.mdx) or a [native app](../../starter/native-app.mdx) runs no server, so it has no service.

## Release images [#release-images]

The workflow builds each app's image for `linux/amd64` and `linux/arm64` and pushes it to `ghcr.io/<owner>/<repository>-<service>`, tagged with its version (`1.2.3`), `1.2`, and `latest`. Run by hand on the default branch, it pushes `edge`. It never runs for tag pushes, so a deleted tag leaves no images behind, and it needs no secret: it uses the workflow's own token.

The values an image compiles in come from repository variables: `NEXT_PUBLIC_APP_URL` for Next.js, the `VITE_*` values for a React + Vite frontend. Set the ones you use before the first release. The packages start private.

## On the server [#on-the-server]

Point the domain's DNS A and AAAA records at the server, and publish a release. Then on the server, next to `compose.yaml`, the `Caddyfile`, and `.env.production` (the whole project, to build there):

```sh
# .env.production: DOMAIN=example.com, the app's variables, and, to run the released images,
# IMAGE_PREFIX=ghcr.io/<owner>/<repository> (TAG=1.2.3 pins a release; latest otherwise)
docker login ghcr.io                             # while the packages are private: a token with read:packages
docker compose --env-file .env.production run --rm web node /app/migrate.mjs   # api when the project has one
docker compose --env-file .env.production up -d  # --build builds the images on the server
```

`deploy` prints these steps, with your repository's `IMAGE_PREFIX` when `origin` is on GitHub. The variables of `.env.example`, and of `apps/api/.env.example` for a frontend and its API, go in `.env.production`; without a website, those of `apps/api/.env.example`. `docker compose logs --follow` shows the logs.

To update, publish a release. Then on the server, run `docker compose --env-file .env.production pull` (or set `TAG` to the new version), the migrations, and `up -d` again.

## Run it again [#run-it-again]

Running `deploy` again writes the files that are missing and never overwrites one: it keeps a `Caddyfile` or workflow you changed, and says so, and stops when `compose.yaml` differs from the one it writes. Move yours away to get the new one.

Compose prefers `compose.yaml` to the Starter's `docker-compose.yml`, so run the local one by name: `docker compose -f docker-compose.yml up --build`. `pnpm docker:dev` does this from Starter v0.27.0.

## Client addresses [#client-addresses]

Caddy is the one proxy of your own in front of the app, and it sets `X-Forwarded-For` to the client's address, so `compose.yaml` gives the public app `TRUSTED_PROXY_HOPS=1`: the API itself, without a website. A frontend's API, reached only through the frontend's server, gets `TRUSTED_PROXY_HOPS=1` too. `CLIENT_IP_HEADER` or `TRUSTED_PROXY_HOPS` in `.env.production` replaces the default, for another proxy in front. See [Client addresses](./index.mdx#client-addresses).

## Before CLI 0.42.0 [#before-cli-0420]

`deploy` wrote a `compose.yaml` only for a frontend and its API, with the frontend's port published and no HTTPS, and refused full-stack projects that deploy with `docker`. The Starter's deploy workflow published one image instead; see [Any container host](../../starter/deploy/container-host.mdx#release-images).
