Dokploy API
Dokploy exposes tRPC-style endpoints under <base>/api/<procedure>.
- Base URL: Dokploy's UI/API port (
http://127.0.0.1:3000on the host by default). SetDOKPLOY_URLandDOKPLOY_API_KEYin the environment; send the key asx-api-key. - Queries are
GETwith a query string (compose.one?composeId=ID). Mutations arePOSTwith a JSON body. - Never print
DOKPLOY_API_KEY, and never dump a rawcomposeFileorenv: both can hold secrets.
dp() { curl -sf -H "x-api-key: $DOKPLOY_API_KEY" "$DOKPLOY_URL/api/$1" "${@:2}"; }
dp_post() { curl -sf -H "x-api-key: $DOKPLOY_API_KEY" -H 'Content-Type: application/json' -X POST "$DOKPLOY_URL/api/$1" -d "$2"; }
Procedures
| Need | Call |
|---|---|
| Inventory (projects, composes, apps, status) | dp project.all (compose entries carry composeId, name, appName, composeStatus) |
| One compose (file, env, source type) | dp "compose.one?composeId=$ID" |
| Save a new compose file (not applied yet) | dp_post compose.update '{"composeId":"ID","composeFile":"..."}' |
| Apply the saved compose (recreates containers) | dp_post compose.deploy '{"composeId":"ID"}' |
| Restart | dp_post compose.stop '{"composeId":"ID"}' then dp_post compose.start '{"composeId":"ID"}' |
| Move between projects | dp_post compose.move '{"composeId":"ID","targetEnvironmentId":"ENV"}' (containers untouched) |
Containers of a stack carry the label com.docker.compose.project=<appName>; on disk the compose lives at /etc/dokploy/compose/<appName>/code/docker-compose.yml.
Gotchas
stop+startuses the on-disk compose and honourspull_policy. Withpull_policy: alwaysand a:latesttag, a "restart" silently upgrades the image. Pin images (a digest is best) and tell the user before any deploy of alateststack.compose.updateonly writes Dokploy's database. Nothing changes untilcompose.deploy.sourceType: rawcomposes are edited through the API.githubcomposes come from the repository (often withautoDeploy): change them in git, not withcompose.update.composeStatus: errormeans the last deployment failed; read the deployment log in the Dokploy UI.- A redeploy reuses anonymous volumes. Images that write config into one at startup keep stale entries; remove the container and its volumes (
docker rm -f -v <container>) and deploy again. - Do not trust a masking regex to catch every secret format. Check any new format by eye, and prefer moving secrets into the compose
envand referencing${VAR}.
Changing an image
- Read the compose, replace the
image:line, show the user a diff. - Take a backup of the current compose file (below).
compose.updatewith the new text, thencompose.deploy.- Poll
compose.oneuntilcomposeStatusleavesrunning, then confirm the containers are healthy and the service answers.
To pin by digest: docker pull <image>, then docker image inspect <image> --format '{{index .RepoDigests 0}}', and use image@sha256:....
Editing a compose with yq
Use mikefarah yq v4 (check yq --version; a different yq of the same name is common). Always dry-run first.
f=$(dp "compose.one?composeId=$ID" | jq -r .composeFile)
nf=$(printf '%s\n' "$f" | yq '.services.web.healthcheck.interval = "60s"')
printf '%s\n' "$nf" | yq -e '.services' >/dev/null # refuse a result with no services
diff <(printf '%s\n' "$f") <(printf '%s\n' "$nf") # show masked in practice; may contain secrets
Then back up, compose.update with jq -n --arg id "$ID" --arg f "$nf" '{composeId:$id,composeFile:$f}', and compose.deploy once the user agrees.
Do not put secrets in a yq expression: it lands in shell history and transcripts.
Backup and restore
- Backup: write
compose.one'scomposeFileto a file created withumask 077, outside any git repository (it holds secrets unmasked). - Restore:
compose.updatewith the backup's contents, thencompose.deploy. Back up the current version before restoring. - Log every change with the compose id, the backup path and how to revert.