Skip to content
Playbook: deploy a Docker app or stack Deploy a single-container Docker app (app.create, app.build) or a Docker Compose stack (stack.deploy with __MZ_PORT__) from an AI agent, then update, roll back, attach a database and verify.

Playbook: deploy a Docker app or stack

Goal: a containerized workload running on one server and served on a domain through nginx with TLS.

Token: operate. Plan: Docker apps and Compose stacks are on every plan; creating a new app or stack counts against the plan’s shared Docker apps & stacks quota (Free 3, Plus 5 per server, Pro and Max unlimited, across all servers; over it → 402 app_limit). On Free, writes through a token are a 30-day trial (then 402 automation_trial_ended). Server: Docker must be installed. Check with servers_inventory {id, kind: "services"}. If it’s missing, run servers_provision {id, body: {components: ["docker"]}} (full) or jobs_create extension.install {id: "docker"} (every plan).

Code in a local folder? Use Deploy code from your AI agent: two calls (apps_source_upload → apps_deploy), no Git remote and no domain needed.

Pick a shape:

You haveUseJob kind
One image (ghcr.io/acme/web:1.4)Docker appapp.create
A project folder on your machineDocker app built on the boxapps_source_upload + apps_deploy (playbook)
A Git repo with a Dockerfile, or one Nixpacks can detectDocker app built on the boxapps_deploy {source: {git}} or app.build
A docker-compose.ymlCompose stackstack.deploy
A Git repo with a compose fileCompose stack built on the boxstack.build
Source code without DockerA runtime site insteadsite.create with siteType (see Create a site)
  1. jobs_schema {type: "app.create"}

  2. jobs_create:

    {
    "id": "<server UUID>",
    "body": {
    "type": "app.create",
    "name": "web",
    "domain": "web.example.com",
    "image": "ghcr.io/acme/web:1.4",
    "port": 3000,
    "env": ["NODE_ENV=production", "LOG_LEVEL=info"],
    "volumes": ["web-data:/data"],
    "memory": "512m"
    }
    }
    • name: 1–32 characters, lowercase letters, digits and dashes, starting with a letter.
    • port: the port the container listens on. MZPanel allocates the host port and the nginx proxy itself.
    • volumes: HOST:CONTAINER[:ro], where HOST is a named volume or an absolute path.
    • Private image: pass registryConnectionId (from registry_connections_list), or registryUser + registryPass (+ registryServer). An inline password is never stored in the job log.
  3. Poll jobs_get until completed. Image pulls can take a few minutes.

  4. Verify: servers_docker_all (or servers_inventory {id, kind: "docker"}) shows the app. jobs_create app.logs {name: "web", lines: 100} returns its logs. Then fetch https://web.example.com.

Build from Git instead: the simplest door is apps_deploy {id, body: {source: {git: {url, branch?, connectionId?}}, db?: "auto"}}, which picks a name, gives the app an instant HTTPS URL and returns a status URL to poll (see the deploy-code playbook). For fine control use app.build {name, git, branch?, builder: auto|dockerfile|nixpacks, dockerfile?, context?, port?, domain?, env?, gitConnectionId?, db?}. gitConnectionId comes from git_connections_list and handles private-repo tokens for you. A new app must answer on its port within 60 seconds of its first start, or the job fails with health_check_failed and the app is left in place for a redeploy.

  1. Write the compose file. The service that should receive web traffic must publish 127.0.0.1:__MZ_PORT__:<container port>. The agent replaces __MZ_PORT__ with the host port it allocates and points the domain’s nginx vhost at it. Keep every other service unpublished, or bound to 127.0.0.1. Since agent 0.2.158 the agent binds any published port without a host IP to 127.0.0.1 on deploy and lists them in the job output ([mz] Bound N published port(s) to 127.0.0.1); set x-mz: {public_ports: true} (top level or per service) only when a port must really be public.

    services:
    app:
    image: ghcr.io/acme/app:2.0
    ports: ["127.0.0.1:__MZ_PORT__:8080"]
    environment:
    DATABASE_URL: postgres://app:secret@db:5432/app
    depends_on: [db]
    db:
    image: postgres:17
    environment:
    POSTGRES_USER: app
    POSTGRES_PASSWORD: secret
    volumes: ["db-data:/var/lib/postgresql/data"]
    volumes:
    db-data:
  2. jobs_create, passing the compose file as a plain string (up to 100,000 characters; the API encodes it for the agent):

    { "id": "<server UUID>",
    "body": { "type": "stack.deploy", "name": "shop", "domain": "shop.example.com",
    "compose": "services:\n app:\n image: ghcr.io/acme/app:2.0\n ports: [\"127.0.0.1:__MZ_PORT__:8080\"]\n" } }
  3. Poll jobs_get. Verify with servers_stacks_all or servers_inventory {id, kind: "stacks"}, then fetch the domain.

NeedAppStack
Restart / stop / startapp.restart · app.stop · app.start {name}stack.restart · stack.up {name}
Change image, env, resourcesapp.update {name, image?, env?, memory?, cpus?, port?, restart?, pull?, recreate?}stack.update {name, compose}
Set or unset env varsapp.env-set {name, vars: ["K=V"]} · app.env-unsetstack.env-set {name, vars} · stack.env-unset
Pull new imagesapp.update {name, pull: true}stack.pull {name}
Auto-update imagesapp.auto-updatestack.auto-update {name, enabled}
Releases and rollbackapp.releases {name} → app.rollbackstack.releases {name} → stack.rollback {name, to} (backups:restore)
Extra domainsapp.domain-add {name, domain} · app.domain-remove · app.domain-primary(edit the compose and vhost via stack.update)
Attach a databaseapp.db-attach {name, engine: mariadb|postgres, db?}: the new password appears only in the live output and the job is never queuedn/a
Path routing (Pro)route.add {domain, path, targetKind: app|stack, target}same
Push-to-deploy webhook (every plan; PR previews from it need Pro)app_webhooks_set {id, name, body} (webhooks:admin)stack_webhooks_set (every plan; PR preview stacks need Pro)
Move or clone to another server (Pro)moves_create {body: {kind: "app", name, srcServerId, dstServerId, mode: move|clone, newDomain?}} (full + backups:restore; a clone needs newDomain)kind: "stack"
Back up nowbackups_run_once {id, body: {targetKind: "app", target: name}}targetKind: "stack"
Removeapp.delete {name} (full + sites:delete)stack.down / stack.delete {name} (full + sites:delete)

Shared variables across a project’s apps and stacks are managed with env_vars_set and applied with projects_env_apply {id} (Pro). app.env-sync and stack.env-sync are not callable directly.

Adopting existing containers (Pro): stack.adopt {project, name, redeploy?} brings a compose project that was started outside MZPanel under management. app.adopt does the same for a single container.

  • tier_required: a Pro-only kind (adoption, previews, path routes, shared variables) on Free or Plus. Report it. Don’t retry.
  • 402 app_limit: the plan’s Docker apps & stacks quota is used (details.used, details.limit, details.tier). Ask the human to delete an app or stack, or upgrade; redeploying an existing name still works.
  • 402 automation_trial_ended: the Free plan’s 30-day API write trial is over. Don’t retry. Tell the human to upgrade to Plus or make the change in the dashboard.
  • stack.deploy succeeds but the domain shows 502: the primary service doesn’t publish 127.0.0.1:__MZ_PORT__:<port>, or the container isn’t listening on that port yet. Check docker.logs {container, lines}.
  • Pull fails with authentication errors: the registry needs credentials. Add a registry connection in the dashboard (/connect/registries) or with registry_connections_create (webhooks:admin), then pass registryConnectionId.
  • 409 server_offline on an env write: env writes are never queued. Wait for the server to come online.