Skip to main content
Every GatoJS project ships a multi-stage Dockerfile that produces a production image from Next.js standalone output. The image runs node server.js as a non-root user and includes the Prisma CLI so you can apply migrations from the same image. Railway builds from this file (see Railway), and you can run it on any container host.

Standalone output

next.config.ts sets output: "standalone". With it, next build writes a server.js to .next/standalone together with only the files from node_modules the server actually uses. The image needs neither the full node_modules nor your source code.

Build stages

The workspace COPY lines in the deps stage sit in a generated region:
Dockerfile
gato generate rewrites this region from the directories under packages/. If you add a workspace package, regenerate so npm ci sees it.

Runtime environment

Dockerfile
  • NODE_ENV=production turns on the production rules of env validation: RESEND_API_KEY becomes required, sample secrets from .env.example are rejected, and modules add their own rules. It also stops the logger from writing to the console (see Logging).
  • PORT=3000 is a default. Platforms such as Railway inject their own PORT, which overrides it.
  • HOSTNAME="0.0.0.0" makes the server listen on all interfaces.
Don’t set HOSTNAME to 127.0.0.1. With that value, unprefixed (default-locale) URLs answer with a 307 redirect to themselves, an endless loop, and the healthcheck won’t catch it because /api bypasses the proxy. Safe values are 0.0.0.0 and ::. localhost works but listens on loopback only, which is useless inside a container.

Prisma CLI in the image

Migrations run with npx prisma migrate deploy, which reads prisma.config.ts. That file imports prisma and dotenv, but the standalone output contains only @prisma/client. The runner stage installs both packages separately:
Dockerfile
These versions are pinned to match package-lock.json. When you upgrade prisma or dotenv in package.json, update them here too; nothing checks that the two stay in sync.
The image has no scripts/, src/, tsx or dev dependencies, so npm run admin:create can’t run inside the container. Run it from your machine against the production database instead (see Railway).

What goes into the build context

.dockerignore keeps local and kit-only files out of the image:
.dockerignore
  • .env and .env.* never enter the image, so local secrets can’t leak into it. Production variables come from the runtime.
  • node_modules, .next and src/generated are rebuilt inside the image.
  • prisma/migrations/ is not excluded, so committed migrations ship with the image. Make sure they are committed: platforms that build from git only see tracked files.

Build and run locally

1

Build the image

The build needs no environment variables; next build skips the env check.
2

Prepare an env file

Create a production env file outside the repository with at least the required variables:
prod.env
Add module variables too, for example API_KEY_PEPPER for api-keys and storage settings for uploads. See Environment variables.
3

Apply migrations

Run the migration command in a one-off container from the same image:
4

Start the server

Then check http://localhost:3000/api/healthcheck. It should return {"status":"ok","db":"ok"}.
If a variable is missing or invalid, the container exits with code 1 right after start and prints a report starting with Nieprawidłowe zmienne środowiskowe (“invalid environment variables”). Read it with docker logs my-app. A restart policy won’t help, because every start fails the same way.

Migrations on deploy

Run npx prisma migrate deploy before the new version starts serving traffic, in a separate container or pre-deploy step from the same image. That way the migrations in the image always match the code.
The kit doesn’t ship migrations, because the schema depends on the modules you install. Create your first one with npx prisma migrate dev --name init and commit the whole prisma/migrations/ folder. See Database and migrations.

Persistent files

The runner creates /app/volumes/uploads, owned by nextjs, in every image. The uploads module’s local provider writes there when you mount a volume at that path and set STORAGE_LOCAL_PATH=/app/volumes/uploads:
Production with local storage outside Railway requires an absolute STORAGE_LOCAL_PATH. See File storage for permissions, S3 and multi-instance setups.

Deploy on Railway

The recommended host, step by step.

File storage

Where production uploads live.