Install for production
This page starts from the quick start install. You add TLS, back up the three places Codex stores data, pin an image version and size the host for print runs.
Add TLS with Caddy
Section titled “Add TLS with Caddy”Codex listens on plain HTTP on port 8080. Put a reverse proxy in front of it that holds the certificate. The example below uses Caddy, which gets and renews a certificate for your domain by itself.
Codex marks its sign-in cookie Secure when the request it sees is HTTPS. Behind a proxy the app sees HTTP, so the proxy must send X-Forwarded-Proto and X-Forwarded-Host. The Caddyfile sets both. Without them, Codex does not mark the cookie Secure, even though the browser uses HTTPS.
- Point a DNS record for your domain at the machine. Open ports 80 and 443 on its firewall.
- Make a folder named
caddybeside yourdocker-compose.yml. Save the two files below into it. - Add
CODEX_DOMAIN=codex.example.comto your.env, with your own domain. - Start the stack with both compose files.
docker compose -f docker-compose.yml -f caddy/docker-compose.yml up -dThe second file removes the published port 8080 from the app, so only Caddy reaches it. Port 80 must stay open, because Caddy uses it to prove to the certificate authority that you own the domain. Keep the caddy-data volume, or Caddy asks for new certificates on every start.
From now on, every docker compose command that starts or recreates containers needs both files, as in step 4. With only the base file, Compose publishes port 8080 again, which bypasses Caddy, and leaves the caddy container running on its own.
The files are in the docs repository: Caddyfile and docker-compose.yml.
# Caddy in front of Codex. Set CODEX_DOMAIN in .env to the host name that points at this machine.# Caddy gets and renews a TLS certificate for that name on its own.{$CODEX_DOMAIN} { encode zstd gzip
reverse_proxy codex:8080 { # Codex marks its sign-in cookie Secure only when it sees https here, so send the scheme and host on. header_up X-Forwarded-Proto {scheme} header_up X-Forwarded-Host {host} }}# Adds Caddy to the production install. Run it with:# docker compose -f docker-compose.yml -f caddy/docker-compose.yml up -d# The first file is your Codex compose file. Set CODEX_DOMAIN in .env first.services: codex: # Only Caddy reaches the app, so drop the published port. ports: !reset []
caddy: image: caddy:2 restart: unless-stopped depends_on: - codex ports: - "80:80" - "443:443" environment: - CODEX_DOMAIN=${CODEX_DOMAIN:?Set CODEX_DOMAIN in .env} volumes: - ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro # Caddy keeps its certificates here. Keep this volume, or it asks for new ones on every start. - caddy-data:/data - caddy-config:/config
volumes: caddy-data: caddy-config:Caddy sets these headers itself and ignores any copy a client sends. The header_up lines state them so the file shows what Codex needs. Caddy logs an “Unnecessary header_up” warning for each of the two lines when it validates the file. Expect those warnings. For Caddy’s own options, see its reverse_proxy reference. Another proxy works if it sends the same two headers.
Check the result with curl https://codex.example.com/health. It answers {"status":"ok","version":"..."} and needs no sign-in.
What to back up
Section titled “What to back up”Codex keeps data in three places. Back up all three.
| Store | Where it lives | What it holds |
|---|---|---|
| Postgres | The codex-pgdata volume |
Books, scenes, sources, users, sign-in sessions and the keys that sign the session cookie. |
| Blob folder | The codex-blobs volume, mounted at CODEX_BLOB_ROOT |
Uploaded files, image renditions and exports. |
| Key ring | The codex-keys volume, mounted at CODEX_DATA_PROTECTION_DIR |
The keys that encrypt the AI keys users save. |
Back up all three at the same time, and keep the key ring apart from the database dump. Codex keeps the key ring outside the database, so that a dump alone cannot decrypt anyone’s AI key.
To dump the database:
docker compose exec -T postgres pg_dump -U postgres -d codex --format=custom > codex.dumpTo copy a volume to a tar file, run a throwaway container that mounts it. Compose prefixes volume names with the project name, so list them first with docker volume ls.
docker run --rm -v <project>_codex-blobs:/data:ro -v "$PWD":/backup alpine tar -czf /backup/codex-blobs.tgz -C /data .docker run --rm -v <project>_codex-keys:/data:ro -v "$PWD":/backup alpine tar -czf /backup/codex-keys.tgz -C /data .To restore, put the three stores back in this order. The database restore needs Postgres running. Stop Codex and the worker while you do it.
- Create the containers and volumes without starting them, then start only Postgres. On a host that already runs Codex, run
docker compose stop codex workerinstead.
docker compose up --no-startdocker compose up -d postgres- Load the dump.
docker compose exec -T postgres pg_restore -U postgres -d codex --clean --if-exists --no-owner < codex.dump- Unpack the two tar files into their volumes.
docker run --rm -v <project>_codex-blobs:/data -v "$PWD":/backup alpine tar -xzf /backup/codex-blobs.tgz -C /datadocker run --rm -v <project>_codex-keys:/data -v "$PWD":/backup alpine tar -xzf /backup/codex-keys.tgz -C /data- Start everything. If you added Caddy, use both compose files, as in the TLS section.
docker compose up -dA restored database without its key ring still opens. Only the saved AI keys are lost.
If you lose the key ring
Section titled “If you lose the key ring”Codex cannot read the AI keys it saved with a key ring it no longer has. Nothing else breaks. When someone drafts with AI or presses Test on an integration, Codex answers not_configured with the message “The saved key can’t be read with this server’s key folder. Enter the key again in Settings → AI.” Each user opens Settings, then AI, and enters the key again.
Users can also back up one book from inside the app. That backup holds the book, not the install, so it does not replace the three stores above.
Upgrade
Section titled “Upgrade”The images have two tags, latest and the full commit SHA of the build. latest moves on every build, so a production file that uses it upgrades on whichever day you next pull. Pin a SHA instead.
- Back up the three stores.
- Pick a build. Ask the running app for its commit.
curl https://codex.example.com/healthreturns a version such as1.0.0+35618f3..., and the part after the plus sign is the commit. Tags on the app image page list the builds. - Set the same SHA for both images in
.env. The names below come from the images the quick start pulls.
CODEX_IMAGE=ghcr.io/codexsuite/codex:<full commit SHA>CODEX_WORKER_IMAGE=ghcr.io/codexsuite/codex-worker:<full commit SHA>- Pull and recreate. These commands include the Caddy file. If you did not add Caddy, leave out the second
-foption.
docker compose -f docker-compose.yml -f caddy/docker-compose.yml pulldocker compose -f docker-compose.yml -f caddy/docker-compose.yml up -dUse the same SHA for the app and the worker, because they share one database schema and one set of job rules. The web service applies database migrations when it starts, and the worker does not (CODEX_DB_MIGRATE=false). After an upgrade the worker can start before the web service has finished migrating. Its job loop logs the error and tries again every 2 seconds, so it recovers by itself once the schema is current.
To go back, set the older SHAs and run the same two commands from step 4. Codex does not reverse migrations, so restore the database backup from before the upgrade when the newer version changed the schema.
Run more than one web host
Section titled “Run more than one web host”Run one codex service. Live updates between processes go through a Postgres notification bridge. The product documents that bridge for events that other processes send to the web host, such as the worker’s job progress. It does not describe web host to web host, so nothing here promises that several web hosts show each other’s changes. Blob storage is also one folder on one disk, so extra web hosts would need a shared disk.
Size the host
Section titled “Size the host”Codex does not state a memory or CPU minimum. These figures come from the code and the defaults:
- A print run for a proof or an export for the printer runs Tectonic in a sandbox. Codex caps its address space at 4 GiB, so keep at least that much free memory for the worker when a book is large.
- One run may take 300 seconds (
CODEX_RENDER_TIMEOUT_SECONDS) and may write a PDF of up to 1024 MB (CODEX_RENDER_MAX_PDF_MB). Lower the limits to fail a runaway run sooner. - One worker runs one export and one proof at a time, and polls for new jobs every 2 seconds. Exports queue behind each other. A longer book makes each run longer, and a second worker is the way to run more at once.
- The worker container writes each run under
CODEX_RENDER_WORK, which defaults to the container’s temp folder. Keep enough free disk for the largest PDF.
Printing also needs a Linux kernel with Landlock ABI 4, which arrived in Linux 6.7. See the requirements for the command that tests your host.
Next steps
Section titled “Next steps”- To see what the worker does and what stops without it, read files and the worker.
- To collect logs and metrics, read logs and monitoring.
- To look up a variable, see the configuration reference.