Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
Docker / Coolify Deployment
This is the second deployment path for DBBASIC Object Server, alongside the bare-VM systemd installer in docs/single-vm-deployment.md. It packages the same server into a container image so it can run under Docker Compose directly, or be deployed with Coolify.
The goal is the same as the bare-VM path: stay boring, stay conservative on first boot, and keep the object edit/run/inspect loop working the same way. This page does not repeat what is not Docker-specific -- permissions, source-write gates, package installs, first-auth setup, and traffic limits are covered in docs/single-vm-deployment.md and the root README.md; read those too.
What Ships in the Image vs. What Must Be a Volume
This is the concept the rest of this page assumes.
The image is stateless. It contains the server code and the installable package fixtures under packages/ -- both of those are tracked in git and rebuilt into the image on every docker build.
Everything the server writes at runtime is state, not code, and must live on a mounted volume outside the image:
- object source under
DBBASIC_OBJECTS_DIR - TSV-backed records, state, logs, versions, schemas, and changelogs under
DBBASIC_DATA_DIR
- identity (accounts, users, sessions, credential hashes)
- the permission policy and audit log
- backups under
DBBASIC_BACKUPS_DIR - the auto-generated admin token (see "First Boot" below)
Dockerfile sets DBBASIC_OBJECTS_DIR=/data/objects and DBBASIC_DATA_DIR=/data/state as the image's default paths, and docker-compose.yml mounts two named volumes at exactly those paths. This mirrors the same separation docs/single-vm-deployment.md keeps between /opt/dbbasic-object-server (the git checkout) and /var/lib/dbbasic-object-server (runtime data) on the bare-VM path -- code and state never share a lifecycle.
That split is what makes the two halves of the deploy story work independently (see "Deploy Cadence" below).
Quickstart (Docker Compose)
From a checkout of this repository:
cp .env.example .env
# edit .env if you want to change any of the conservative defaults
docker compose up --build
This builds the image, starts the object-server service bound to 0.0.0.0:8001 inside the container, and publishes it on localhost:8001. Watch the logs for the first-boot admin token message (see "First Boot" below), then:
curl http://localhost:8001/health
Object source and runtime data persist on the objects and data named volumes declared in docker-compose.yml, so docker compose up --build after a code change keeps existing objects, records, and identity intact.
docker compose up also starts a second service, object-daemon: the same image running object_daemon.py instead of uvicorn. See "The Daemon" below.
The Daemon
object_daemon.py is the server's background worker: scheduled tasks (the schedules packages declare, and the methods objects schedule for themselves with _schedule(interval_seconds, method_name)), the queue, change dispatch, and the retention and cleanup passes. The HTTP server never runs any of these itself, so without the daemon the box answers requests while everything time-driven silently stops -- an object that refreshes a cache every half hour serves the first copy forever.
In docker-compose.yml it is the object-daemon service:
- Same image, same env file, same two volumes as
object-server; only
the command differs (python object_daemon.py). It publishes no port.
- Starts after
object-serveris healthy, so the server's first boot
owns creating the data directory and the generated admin token.
- Its own health check. The image's
HEALTHCHECKasks port 8001,
which the daemon does not serve, so the service overrides it: a running daemon rewrites .daemon_heartbeat in the data directory every 30 seconds, and the check passes while that file is under two minutes old. The same heartbeat is what GET /daemon/status reads to report daemon_not_running.
- Run exactly one. Two daemons on the same volumes would both run
every due task. Do not scale this service.
The scheduler pass needs the scheduler trigger object, which the system-triggers package installs; until it is installed the daemon's boot banner says Scheduler: no scheduler object and tasks wait. Cron schedules also need croniter (the scheduler extra), which the image installs: interval schedules (_schedule) and one-time tasks do not need it, but every schedule the shipped packages declare is cron, so without it no scheduled pass could run. The banner says Croniter: available, and GET /daemon/status reports croniter_available: true. (An image you build yourself from a different Dockerfile must install it too: pip install 'croniter>=2.0'; a daemon without it says so in the banner, in GET /daemon/status as the cron_needs_croniter problem, and in each cron task's own error.)
On Coolify, deploy docker-compose.yml as a Compose resource and both services come up together. If you deploy the plain Dockerfile as an application instead, add a second application from the same repository with the start command python object_daemon.py, the same environment variables, and the same two volumes mounted at /data/objects and /data/state, with its health check disabled or pointed at the heartbeat as above.
Logs: docker compose logs -f object-daemon.
Coolify Deployment
Coolify can deploy this repository two ways:
- Dockerfile application -- Coolify detects the
Dockerfileat the repo
root and builds/runs it directly.
- Docker Compose resource -- Coolify deploys
docker-compose.yml
directly.
The Compose path is the cleaner one for this project, because it declares the two persistent volumes explicitly instead of leaving them implicit. Prefer it unless you have a reason to use the plain Dockerfile path.
Either way, in Coolify:
- Create the application from this repository, pointing at the
Dockerfile or docker-compose.yml per the choice above.
- Configure persistent storage. In Coolify's Storage / Persistent
Storage settings, add two volumes (or reuse the ones declared in docker-compose.yml if you deployed it as a Compose resource) mapped to the same container paths the image expects:
/data/objects
/data/state
These must match DBBASIC_OBJECTS_DIR and DBBASIC_DATA_DIR. If you change one, change the other.
- Set environment variables through Coolify's Environment Variables UI,
using .env.example as the list of what to set and why. At minimum, decide whether to set DBBASIC_ADMIN_TOKEN explicitly (recommended once this is a real deployment) or leave it unset for the container to generate one on first boot.
- Enable health-check-based deploys. The image's
HEALTHCHECK
instruction (and docker-compose.yml's healthcheck: block) call GET /health. Point Coolify's deployment health check at the same endpoint so it waits for a healthy container before cutting traffic over on redeploy, giving zero-downtime deploys for server-code changes.
- Put a domain in front of it. Coolify's own proxy handles TLS and
hostname routing to the container's published port, the same way Caddy sits in front of, not inside, the systemd unit on the bare-VM path. This repository's docs use object.dbbasic.com as the example public domain; use your own.
Deploy Cadence
There are two independent kinds of change here, and only one of them needs an image rebuild:
- Server code changes (anything in this git repository) require
rebuilding and redeploying the image. Under Coolify this is a normal git-push-to-deploy flow: push to the branch Coolify watches, it rebuilds the image, runs the health check, and cuts over.
- Object, schema, and record edits made live through the admin HTTP API
(the same API described in the root README.md and docs/single-vm-deployment.md) land directly on the persistent volumes. They take effect on the next request, with no image rebuild and no redeploy, exactly like the bare-VM deployment's edit/run/inspect loop.
This is the reason the volume split above exists: redeploying the image never touches /data/objects or /data/state, so in-flight object work survives ordinary code deploys.
A packages/<name>/ change (in git) needs BOTH steps, not either/or. An image rebuild brings the new packages/ source into the image, but /data/objects and /data/state/schemas are the persistent volumes the running container actually serves from — the same separate-copy split docs/single-vm-deployment.md's Upgrade section documents for the bare-VM case, and the entrypoint does not auto-sync it. After the new image is live, still call POST /packages/{id}/install ({"allow_replace": true}, admin-token gated) for the changed package, confirm install.objects[].status says "updated", and expect the object module cache to need the container's next natural restart (or force one) to pick it up. Skipping this step is a silent no-op exactly like the bare-VM case: new image, tests green, health check passes, and the container keeps serving the old package code with no error anywhere.
First Boot: the Admin Token
If DBBASIC_ADMIN_TOKEN is not set, scripts/docker-entrypoint.sh (the image's container entrypoint, after it has dropped to dbbasic) generates one, writes it to a file under the persistent data volume so it survives restarts and rebuilds, and prints it once, clearly, to the container's logs:
docker compose logs object-server | grep -A4 "generated a new admin token"
or, in Coolify, check the application's log viewer after first deploy.
The token is never baked into the image and never written anywhere in the git checkout -- only into the runtime-only data volume. It is not regenerated or overwritten on later boots.
Once you have confirmed the deployment works, set DBBASIC_ADMIN_TOKEN explicitly (in .env for Compose, or in Coolify's environment variables UI) rather than relying on the generated value. That gives you a token you control and can rotate deliberately, and it is required if you ever need to recreate the data volume from a backup.
User Objects and External Identity
Two variables let another app's users use this server with their own tokens:
DBBASIC_IDENTITY_VERIFY_URL-- the app's token verify endpoint (e.g.
https://app:8443/api/auth/verify/ on the Compose network). Unset means off. It must be https:// (plain http:// only to a loopback host: a Compose service name is not loopback) and a trusted internal service: every caller's token is forwarded to it. Verified users are never admin.
DBBASIC_IDENTITY_VERIFY_SECRET-- a shared secret this server sends to the
verify endpoint in X-DBBASIC-Verify-Secret so it can refuse anyone else. Required for a non-loopback URL (16 to 512 visible characters); never logged.
DBBASIC_IDENTITY_AUDIENCE-- this server's name. The verify endpoint
must answer with "audience": "<this name>", or the token is refused. Required.
DBBASIC_IDENTITY_VERIFY_ALLOWED_ROLES-- comma-separated roles the verify
endpoint may confer (e.g. viewer,editor). Default: none. Admin role names are never conferred, listed or not.
DBBASIC_IDENTITY_CACHE_TTL_SECONDS-- how long a verified token is
trusted before the verify service is asked again. Default 30, at most 60 (a larger value is clamped, with a startup warning). Lower it for faster revocation, or have the app call POST /admin/identity/sources/forget when it revokes a token. While the verify service is down, requests carrying a token get 503 + Retry-After.
DBBASIC_ENABLE_USER_SOURCE_WRITES-- defaultfalse. Lets those users
create and change their own u_<id>_ objects. Writes are refused (403) unless user objects can run sandboxed on this host (see "Kernel Requirements for User Code" above), so the flag alone never hands account holders code execution in the container.
Per-customer limits for those users, all in .env (0 turns one off): DBBASIC_MAX_CONCURRENT_EXECUTIONS_PER_USER (default 3, so one customer cannot fill the shared 8 slots), DBBASIC_USER_MAX_OBJECTS (100), DBBASIC_USER_MAX_STATE_BYTES (5 MiB per object) and DBBASIC_USER_MAX_FILES_BYTES (100 MiB per user). If you set DBBASIC_ENABLE_PERMISSION_ENFORCEMENT=true, every request is enforced, whatever else is wrong: an invalid policy answers 503 to everyone but the admin token (which repairs it with PUT /permissions/policy), and with no sign-in path such as DBBASIC_ENABLE_PASSWORD_LOGIN=true only the admin token and public grants get in. Each problem is a WARNING in the container log at startup and an alert in GET /admin/status. The entrypoint always provides an admin token, the one thing enforcement refuses to start without. An empty data directory with no policy yet starts enforced as deny-all, and the admin token bootstraps it. DBBASIC_ALLOW_START_WITH_BLOCKED_ENFORCEMENT no longer runs the container unenforced; to do that on purpose, set DBBASIC_ENABLE_PERMISSION_ENFORCEMENT=false (and DBBASIC_ENABLE_PERMISSION_AUDIT=true to watch decisions).
A hosted, multi-user deployment should set DBBASIC_REQUIRE_PERMISSION_ENFORCEMENT=true in .env as well: the container then refuses to start (one Refusing to start: ... line in the log, and uvicorn exits) unless DBBASIC_ENABLE_PERMISSION_ENFORCEMENT=true; audit mode alone refuses too. A lost or mistyped enforcement flag then stops the container instead of serving every customer unfenced. Unset, it changes nothing.
Details: single-vm-deployment.md and permissions-model.md.
How the Image Is Built
The code is copied into /opt/dbbasic-object-server and run from there; it is not pip-installed (an editable install put a finder on every interpreter start, about 8 ms each, including every sandbox worker boot). Only the dependencies are installed, in a layer before the source, so a code change rebuilds only the layers after it: uvicorn and websockets (the server extra) and croniter (the scheduler extra, for the daemon's cron schedules). The same list is in pyproject.toml; a test fails if the Dockerfile and the two extras ever disagree. The top-level modules are compiled at build time, so a start does not compile them and a read-only root filesystem works (keep /data writable). There is no curl in the image: the HEALTHCHECK is a one-line Python (http.client) request to /health, and docker-compose.yml uses the same command. From a shell in the container, run Python from /opt/dbbasic-object-server (the default working directory) so the modules import.
Which commit is running
GET /admin/status (admin only; /health does not show it) reports build_commit next to version, and the startup line prints it, so a rebuild can be confirmed from the server itself. The image cannot find it on its own: the build context has no .git (a tree made with git archive never has one), so pass it in:
BUILD_COMMIT=$(git rev-parse --short HEAD) docker compose build
docker build --build-arg BUILD_COMMIT=$(git rev-parse --short HEAD) -t dbbasic-object-server .
The build writes it to a BUILD_COMMIT file beside the server code. The server reads, in order, the DBBASIC_BUILD_COMMIT environment variable, then that file, and otherwise reports null. A value that is not 7 to 40 hex characters is treated as unknown. Compose with no BUILD_COMMIT set builds with an empty value.
Performance Defaults
The image is built on python:3.14-slim, and .env.example sets DBBASIC_WORKER_POOL_SIZE=4 with DBBASIC_OBJECT_TIMEOUT_SECONDS=5. Without the pool every object call starts a fresh Python interpreter (about 9 req/s on an Apple Silicon Mac in Docker); with four warm workers a trivial object GET measured roughly 1,700 req/s on Python 3.12 and 2,000 req/s on 3.14. Isolation and the timeout are unchanged. Set the pool to 0 to turn it off; see traffic-limits.md.
Optional Tools Image
The default image is the server (the server itself is stdlib-only; the image adds just uvicorn, websockets and croniter). Objects ported from older servers sometimes import a few third-party libraries (images, YAML, HTTP, Markdown). For those, build the tools target, which adds pinned pillow, pyyaml, requests and markdown on top of the same server (about 40 MB more). An object that imports one of them on the default image answers 500 No module named '...':
docker build --target tools -t dbbasic-object-server:tools .
docker build . and docker-compose.yml still build the default image. Heavy OCR and machine-learning stacks (tesseract, paddle, easyocr, opencv) are deliberately left out: run them as their own service and call it from an object.
Kernel Requirements for User Code
User-namespace objects (u_<uid>_*) run as a separate OS user behind a Landlock sandbox (runtime-contract.md "User Object Isolation"). That needs Linux >= 6.7 (Landlock ABI >= 4) with Landlock enabled in the kernel's LSM list -- Ubuntu 24.04's 6.8 kernel qualifies -- and the sandbox launcher the image starts by itself. On a host that does not qualify, user objects return HTTP 503 and the log says why; admin, system and package objects are unaffected. A container shares the host's kernel, so the ABI is a property of the Docker host (or the VM under Docker Desktop/OrbStack), and the container runtime's seccomp profile must allow the landlock_* syscalls (recent Docker defaults do). Check from inside the running container, as the server user:
docker compose exec -u dbbasic object-server python object_sandbox.py --status
The verdict line says whether user objects run and how: the sandbox uid, whether each worker has its own network namespace, the Landlock ABI, and whether UDP is controlled.
The -u dbbasic matters. The launcher answers only the server's own user, so the same command as root (the default for docker compose exec) cannot see it. The verdict then reads cannot tell as this user: run this as the service user (docker compose exec -u dbbasic ... rather than REFUSED, and the command still exits 1: it has not checked anything.
How the container starts
The container starts as root, and the entrypoint (/usr/local/bin/dbbasic-entrypoint, a root-owned copy of scripts/docker-entrypoint.sh) does exactly two things with that:
- starts
object_sandbox_launcher.py(a root-owned copy, run with `python -I
-S) in the background. It is the only root process, and its only job is to start each user-object worker as dbbasic-sandbox`, a second user the image creates that owns no file. If it ever exits, its workers die with it, user objects are refused, and the entrypoint restarts it after 5 seconds;
- re-runs itself as
dbbasicwithsetpriv(real, effective and saved ids;
no supplementary groups), and from there everything -- the admin-token step, uvicorn or the daemon -- runs unprivileged, as before.
It also closes /data/objects and /data/state to other users (mode 0700), which fixes volumes created by older images; the server checks again before every user-object run.
- No extra capabilities. Docker's defaults (
SETUID,SETGID,CHOWN,
KILL) are enough. A profile that drops them (cap_drop: [ALL]) breaks the switch to dbbasic.
--cap-add SYS_ADMINwould let the launcher give every worker its own
empty network namespace (no network at all, UDP included, on any Landlock ABI). It also hands the whole container a very broad capability, so it is not the default; on an ABI 4 host without it, the status says udp: NOT controlled (see runtime-contract.md "What this does not cover").
- One launcher per container. The
object-daemonservice runs the same
entrypoint, so it has its own launcher for the user objects it runs on a schedule; nothing is shared between the containers but the volumes.
- Started as non-root (
--user, KubernetesrunAsNonRoot) the entrypoint
skips the launcher and user objects are refused, with that reason in the status. DBBASIC_SANDBOX_LAUNCHER=off does the same on purpose.
- One-off commands:
docker compose execnow defaults to root. Use
docker compose exec -u dbbasic ... for anything that writes to the volumes (for example object_identity_cli.py), so the files stay the server's.
If a host cannot meet this, do not enable user code on it. Never set DBBASIC_USER_CODE_ISOLATION=unsafe-dev on a server: it runs user code without the wall and exists for development machines (macOS).
See Also
For everything not specific to Docker -- write gates, package installs, permission audit/enforcement, traffic limits, backups, and bootstrapping the first admin user and password login -- see:
docs/single-vm-deployment.md- the root
README.md, especially "First Auth Setup" and
"Public Repository Safety"
Security Notes
These mirror the root README's "Public Repository Safety" checklist:
- Never commit a real
.env. Only.env.example(placeholder values and
comments) belongs in git; .env is git-ignored.
- Never bake a real admin token, password hash, or session secret into an
image layer. The entrypoint's generated token is written only to the mounted data volume, not to any path that gets committed or that survives outside that volume.
- Treat the persistent data volume as containing credentials-equivalent
data: it holds the admin token file, identity credential hashes, and session records. Back it up and restrict access to it the same way you would /var/lib/dbbasic-object-server on the bare-VM path.
- Do not commit real IPs, hostnames, or deployment-specific details into
this repository, including into Coolify configuration you might otherwise be tempted to paste into a doc or issue.