Playbook: deploy a Docker app or stack
Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.
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 have | Use | Job kind |
|---|---|---|
One image (ghcr.io/acme/web:1.4) | Docker app | app.create |
| A project folder on your machine | Docker app built on the box | apps_source_upload + apps_deploy (playbook) |
| A Git repo with a Dockerfile, or one Nixpacks can detect | Docker app built on the box | apps_deploy {source: {git}} or app.build |
A docker-compose.yml | Compose stack | stack.deploy |
| A Git repo with a compose file | Compose stack built on the box | stack.build |
| Source code without Docker | A runtime site instead | site.create with siteType (see Create a site) |
Single-container app
Section titled “Single-container app”-
jobs_schema {type: "app.create"} -
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(fromregistry_connections_list), orregistryUser+registryPass(+registryServer). An inline password is never stored in the job log.
-
Poll
jobs_getuntilcompleted. Image pulls can take a few minutes. -
Verify:
servers_docker_all(orservers_inventory {id, kind: "docker"}) shows the app.jobs_create app.logs {name: "web", lines: 100}returns its logs. Then fetchhttps://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.
Compose stack
Section titled “Compose stack”-
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 to127.0.0.1. Since agent 0.2.158 the agent binds any published port without a host IP to127.0.0.1on deploy and lists them in the job output ([mz] Bound N published port(s) to 127.0.0.1); setx-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.0ports: ["127.0.0.1:__MZ_PORT__:8080"]environment:DATABASE_URL: postgres://app:secret@db:5432/appdepends_on: [db]db:image: postgres:17environment:POSTGRES_USER: appPOSTGRES_PASSWORD: secretvolumes: ["db-data:/var/lib/postgresql/data"]volumes:db-data: -
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" } } -
Poll
jobs_get. Verify withservers_stacks_allorservers_inventory {id, kind: "stacks"}, then fetch the domain.
Day-2 operations
Section titled “Day-2 operations”| Need | App | Stack |
|---|---|---|
| Restart / stop / start | app.restart · app.stop · app.start {name} | stack.restart · stack.up {name} |
| Change image, env, resources | app.update {name, image?, env?, memory?, cpus?, port?, restart?, pull?, recreate?} | stack.update {name, compose} |
| Set or unset env vars | app.env-set {name, vars: ["K=V"]} · app.env-unset | stack.env-set {name, vars} · stack.env-unset |
| Pull new images | app.update {name, pull: true} | stack.pull {name} |
| Auto-update images | app.auto-update | stack.auto-update {name, enabled} |
| Releases and rollback | app.releases {name} → app.rollback | stack.releases {name} → stack.rollback {name, to} (backups:restore) |
| Extra domains | app.domain-add {name, domain} · app.domain-remove · app.domain-primary | (edit the compose and vhost via stack.update) |
| Attach a database | app.db-attach {name, engine: mariadb|postgres, db?}: the new password appears only in the live output and the job is never queued | n/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 now | backups_run_once {id, body: {targetKind: "app", target: name}} | targetKind: "stack" |
| Remove | app.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.
Common failures
Section titled “Common failures”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.deploysucceeds but the domain shows 502: the primary service doesn’t publish127.0.0.1:__MZ_PORT__:<port>, or the container isn’t listening on that port yet. Checkdocker.logs {container, lines}.- Pull fails with authentication errors: the registry needs credentials. Add a
registry connection in the dashboard (
/connect/registries) or withregistry_connections_create(webhooks:admin), then passregistryConnectionId. 409 server_offlineon an env write: env writes are never queued. Wait for the server to come online.