Guides

Recipes

Copy-paste workflows for common shapes, from a static site to CI deploys.

Each recipe is a small, complete workflow. They assume a signed-in account (ant colony signup) only where remote machines are involved; local recipes need nothing but Docker and the CLI.

A static site on this machine

A tiny Dockerfile is all the detection needs; ant nest init sees it and writes build: dockerfile, run: container.

mkdir mysite && cd mysite

cat > index.html <<'EOF'
<h1>Hello from Ant</h1>
EOF

cat > Dockerfile <<'EOF'
FROM python:3-alpine
WORKDIR /site
COPY index.html .
EXPOSE 8080
CMD ["python", "-m", "http.server", "8080"]
EOF

ant nest tools                # Docker present, daemon answering
ant nest init --port 8080     # writes ant.yaml
ant trail deploy local        # build + run; prints the container and URL
ant trail status

Change and redeploy with ant trail deploy local again; ant trail logs --tail 50 shows the container output. ant trail destroy local --yes removes the container and the images Ant built for it.

A Node API with Postgres via compose

Ant keeps your compose file as the source of truth. Every service that declares build: is built, and repository services are pulled.

# compose.yaml
services:
  api:
    build: .
    ports: ["3000:3000"]
    environment:
      DATABASE_URL: ${DATABASE_URL}
    depends_on: [db]
  db:
    image: postgres:17
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: app
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:
ant nest init --build none --run compose --file compose.yaml
ant nest edit secret add DATABASE_URL     # resolved at deploy time, never stored
export DATABASE_URL='postgres://app:secret@db:5432/app'
ant trail deploy local
ant trail status
ant trail logs local db --tail 50         # one service's logs

The ${DATABASE_URL} reference is filled in at deploy time; for a team, keep the value in a manager and name it as a provider instead of exporting it. See Secrets. To run the same stack on a machine, set machine: prod and deploy with ant trail deploy prod; the compose file is resolved here and shipped, and each build: service is built on the machine.

A container with a domain through Caddy

Domains are opt-in and route through the managed Caddy. For a container project, the domain can route to deploy.port and needs no --service.

ant nest edit domain add --subdomain hello   # → hello.localhost
ant trail deploy local                        # redeploy applies the route
curl http://hello.localhost
ant nest edit domain list

Check the proxy if the name does not answer: ant nest tools caddy status. For a remote machine, name the real hostname and point its DNS at the machine:

ant nest edit domain add app.example.com
ant trail deploy prod        # refused if the machine's Caddy is unreachable

Ports 80/443 must be open on the machine for ACME and app traffic. To keep a deployment off Caddy entirely, deploy with --no-caddy. See Configuration.

Pulling from a private registry

With deploy.registry set, a source-built remote deploy builds here, pushes <host>/<repository>/<app>:<release>, and the machine pulls it. The password comes from the environment and travels with the deploy as a short-lived, worker-side credential; it is never written to ant.yaml or the machine.

# ant.yaml
deploy:
  registry:
    type: external
    host: ghcr.io
    repository: acme/api
    username: acme
export ANT_REGISTRY_PASSWORD=…     # masked in CI
ant trail deploy prod              # build here, push, machine pulls

The image-only form takes the registry-qualified reference directly:

export ANT_REGISTRY_USERNAME=acme ANT_REGISTRY_PASSWORD=…
ant trail deploy --image ghcr.io/acme/api:1.4.2 --pull --machine prod --port 3000

On a machine shared by several people, prefer a one-time docker login on the machine and omit ANT_REGISTRY_PASSWORD, so the pull credential does not ride every deploy. See Remote deploy.

The same app on two machines

Two deployments, one per machine; server: overrides the project's base target per environment, and each gets its own resource name.

# ant.yaml
app: api
deploy:
  run: container
  port: 3000
deployments:
  west:
    server: west
  east:
    server: east
ant nest machines add west --host 203.0.113.10 --ssh-key ~/.ssh/id_ed25519
ant nest machines add east --host 203.0.113.20 --ssh-key ~/.ssh/id_ed25519

ant trail deploy west         # builds on west, runs there
ant trail deploy east         # builds on east, runs there
ant trail status west
ant nest containers list --machine east

Each deploy builds on its own machine. To ship one build to both, push with a registry (ant haul --push with deploy.registry) and deploy the same --image on each machine. Branch and environment are part of every name, so the two never collide. See Configuration.

Database access via a tunnel

ant nest tunnel forwards a local port to a container port on a machine over iroh; nothing is exposed on the machine's network interfaces, and the listener is bound to 127.0.0.1 on your side.

ant nest containers list --machine prod     # find the exact container name
ant nest tunnel --machine prod --container api-prod-db-1 --port 5432 --local 15432
# Forwarding 127.0.0.1:15432 -> prod container api-prod-db-1:5432 over iroh; Ctrl-C to stop

# in another shell:
psql "postgres://app:secret@127.0.0.1:15432/app"

Pass the container port (5432), not a published host port, and only running, Ant-managed containers are valid targets. Opening a tunnel needs the deploy capability on that machine. See Tunnels.

A pre-built image from CI

Create a one-time ci-role account for the pipeline, store its exported bundle as a CI secret, and deploy the image the pipeline built. The full setup is in CI; the essence:

# once, on a machine you administer:
ant colony invite --role ci --machine prod

# once, wherever you keep the pipeline's account:
ant colony signup --name ci
ant colony join --token "$(cat invite.txt)" --alias prod
ant colony export --out ant-ci.json      # store as the ANT_BUNDLE secret
# .github/workflows/deploy.yml
jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      ANT_MACHINE: prod
      ANT_PASSPHRASE: ${{ secrets.ANT_PASSPHRASE }}
    steps:
      - name: Install ant
        run: |
          curl -fsSL https://ants-docs.pages.dev/dl/install.sh | sh
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
      - name: Sign in
        env:
          ANT_BUNDLE: ${{ secrets.ANT_BUNDLE }}
        run: |
          printf '%s' "$ANT_BUNDLE" > /tmp/ant-ci.json
          ant colony login --bundle /tmp/ant-ci.json
      - name: Register the machine
        run: ant nest machines add prod --node-id "${{ vars.ANT_MACHINE_NODE_ID }}"
      - name: Deploy
        run: ant trail deploy --image ghcr.io/org/app:"$GITHUB_SHA" --pull --json

Split build and deploy when the build is slow: ant haul --push --release "$GITHUB_SHA" in one job needs deploy.registry and a registry password; the deploy job then only runs the pushed image. A ci role can deploy and roll back, but cannot change the roster or read the audit log.

A staged rollout with groups

A group gives the projects on one machine a shared docker network plus shared env, secrets, and base domains. It does not order the rollout: you deploy stage by stage, and each member is staged and health-gated on a remote nest before it replaces the running release. Both projects target the machine (machine: prod in each ant.yaml).

# once:
ant nest groups create backend --target-machine prod --domain example.com
ant nest groups add backend api worker    # sets group: backend in each project

# stage 1: the API
cd api
ant trail deploy prod          # stages the new container, then swaps
ant trail status prod
ant trail logs prod --tail 50

# stage 2, once the API is verified: the worker
cd ../worker
ant trail deploy prod

Members reach each other by container name on the group network, so the old and new stages can talk during the window. Give the remote projects a zero_downtime: true and a health_check to make each swap and probe explicit; blockers (a writable mount, container_name, named read-write volumes) fall back to a staged replace with a warning. Local members replace in place. For a remote compose or stack member, ant trail rollback re-applies the stored release record; for a local member or an older deploy, pin the previous release's images in the file and deploy again. See Groups and Remote deploy.

Next

Copyright © 2026