Docker deployment
Deploying the ExecKernel HTTP API means running an HTTP entry point and a PHP service around a persistent session database. Your application calls the HTTP entry point; the PHP service loads the configured graph, executes the requested operation and saves the session in SQLite. Replacing a container should preserve the database and the graph definitions needed to resume those executions.
This guide sets up a separate deployment rehearsal, verifies a session across a restart and explains the update procedure. It assumes an API source checkout, a nearby engine checkout containing the revision locked by that API, and Docker with Compose and Buildx, Bash, Python 3 and curl. Run the commands from the API repository root. For the first explanation of the HTTP session operations, see the HTTP API Quick Start: start creates an execution, next saves an accepted choice and resume retrieves its saved position.
Separate the services from the data
Section titled “Separate the services from the data”The supplied compose.yaml defines two services:
| Component | Responsibility | What must survive replacement |
|---|---|---|
web: Nginx on container port 8080 |
Accept HTTP, apply ingress limits and forward API requests through FastCGI. | Its reviewed configuration and the selected image. |
api: PHP-FPM on container port 9000 |
Load configuration, prepare SQLite, run the engine and handle session requests. | Its image, configuration and compatible graph catalogue. |
sessions volume at /var/lib/execkernel |
Store the SQLite session database and its working files. | The volume itself and independently stored backups. |
Graph catalogue at /app/resources/graphs |
Supply the JSON definitions selected by graph code or numeric ID. | The same definitions and identities used by saved sessions. |
Token file at /run/secrets/api_token |
Admit callers to this deployment. | A securely managed credential readable by the runtime. |
Only Nginx has a host port. PHP-FPM is reachable through the Compose backend network, which is marked internal. Both containers run as nonroot users with read-only root filesystems; temporary files use /tmp, and SQLite uses the writable volume. The catalogue included in the image is replaceable through the supplied deploy/compose.graphs.yaml override.
These portions of the supplied Compose file identify the persistent state and the host boundary:
services: api: environment: EXECKERNEL_SQLITE_PATH: /var/lib/execkernel/sessions.sqlite EXECKERNEL_GRAPH_DIR: /app/resources/graphs EXECKERNEL_API_TOKEN_FILE: /run/secrets/api_token volumes: - sessions:/var/lib/execkernel networks: - backend web: ports: - "${EXECKERNEL_BIND:-127.0.0.1}:${EXECKERNEL_PORT:-4320}:8080"networks: backend: internal: truevolumes: sessions:This is an explanatory excerpt; use the complete repository compose.yaml in the commands below. The API does not expose a TCP database service. SQLite is a file-backed store used by PHP inside the API container.
Build and record the deployment images
Section titled “Build and record the deployment images”Select the API revision you intend to deploy before building. The local build helper reads composer.lock, locates that exact engine commit in the engine checkout and packages its Git tree. Uncommitted engine changes and another branch’s current tip are not the build input.
set -euo pipefailgit rev-parse HEADEXECKERNEL_API_IMAGE=execkernel-api:production-check \EXECKERNEL_WEB_IMAGE=execkernel-web:production-check \ ./deploy/build-local.sh ../execkernel
docker image inspect execkernel-api:production-check --format '{{.Id}}'docker image inspect execkernel-web:production-check --format '{{.Id}}'The helper builds the API and web targets from the repository’s Dockerfile. It supplies the locked engine archive to Composer without requiring a GitHub credential for that archive. The build still needs its other dependencies and pinned base images to be available. The next step records the resulting immutable local image IDs, so retagging an image later does not silently change this rehearsal.
This is a local source-build procedure. If you choose a registry artifact instead, separately verify its availability and provenance, and pin the artifact’s digest. A local build does not establish that a public image tag has been published.
Give the rehearsal its own credential and configuration
Section titled “Give the rehearsal its own credential and configuration”Use an unused local port and a distinct Compose project name. Here the project is execkernel-production-check, with HTTP on 127.0.0.1:4321. Its named volume is separate from other Compose projects.
The token belongs to the service, not to an end user or a session. The following commands create a private host directory, generate the token and prepare a curl header file without displaying the credential. The token file is readable inside the nonroot container; its parent directory protects it on the host.
export OPS_DIR="$PWD/.secrets/production-check"mkdir -p "$OPS_DIR"chmod 700 "$OPS_DIR"
python3 - <<'PY'import os, secrets, subprocessfrom pathlib import Path
ops = Path(os.environ["OPS_DIR"])token = secrets.token_hex(32)with (ops / "api-token").open("x") as handle: handle.write(token + "\n")(ops / "api-token").chmod(0o444)(ops / "auth.header").write_text("Authorization: Bearer " + token + "\n")(ops / "auth.header").chmod(0o600)
def image_id(tag): return subprocess.check_output( ["docker", "image", "inspect", tag, "--format", "{{.Id}}"], text=True ).strip()
settings = { "EXECKERNEL_BIND": "127.0.0.1", "EXECKERNEL_PORT": "4321", "EXECKERNEL_SESSION_TTL_SECONDS": "86400", "EXECKERNEL_API_IMAGE": image_id("execkernel-api:production-check"), "EXECKERNEL_WEB_IMAGE": image_id("execkernel-web:production-check"), "EXECKERNEL_API_TOKEN_FILE": str(ops / "api-token"),}(ops / "deployment.env").write_text( "".join(f"{key}={value}\n" for key, value in settings.items()))(ops / "deployment.env").chmod(0o600)PYThe exclusive open("x") stops the command from replacing an existing token. Use a new rehearsal directory when repeating initial setup. The environment example shows the same settings for operators who manage the file themselves.
Define a short command for this particular project. Clear exported values for these keys first because shell variables take precedence over a Compose environment file:
unset EXECKERNEL_BIND EXECKERNEL_PORT EXECKERNEL_SESSION_TTL_SECONDSunset EXECKERNEL_API_IMAGE EXECKERNEL_WEB_IMAGE EXECKERNEL_API_TOKEN_FILE
ekcompose() { docker compose --env-file "$OPS_DIR/deployment.env" \ -p execkernel-production-check -f compose.yaml "$@"}
ekcompose up -d --no-build --pull never --waitexport EXECKERNEL_BASE_URL=http://127.0.0.1:4321curl --fail --silent --show-error "$EXECKERNEL_BASE_URL/healthz"Startup validates the token and every catalogue entry, applies ordered database migrations and verifies their recorded checksums. A successful health response contains "status":"ok" and a request trace. The API container’s own Docker health check only tests the FPM port; the web health check requests /healthz through Nginx and PHP, including the runtime’s database and catalogue checks.
If startup fails, use ekcompose logs --tail 50 api web and ekcompose ps. Check the token’s readability, catalogue validity, volume permissions and free host port. The runtime keeps configuration details and stack traces out of its HTTP bootstrap error; the log identifies the failure class. SQLite backup, recovery and health checks explains the checks’ limits.
Save a known session before restarting
Section titled “Save a known session before restarting”An operational rehearsal needs an execution whose expected state you know. The catalogue shipped with the API includes demo-flow: node 1 offers edge 10, which ends at node 2. We use that small graph to check persistence; the deployment can serve any compatible graph in its configured catalogue.
Start the execution and retain its response in the private directory:
curl --fail-with-body --silent --show-error \ "$EXECKERNEL_BASE_URL/execkernel/session/start" \ --header "@$OPS_DIR/auth.header" \ --header 'Content-Type: application/json' \ --data '{"flow":"demo-flow","lang":"es"}' \ --output "$OPS_DIR/session.json"
SESSION_ID="$(python3 -c \ 'import json,sys; print(json.load(open(sys.argv[1]))["session_id"])' \ "$OPS_DIR/session.json")"The response contains the generated session_id and state.current_node: 1. The catalogue’s example text is Spanish, so this check requests es. Now choose its only edge:
curl --fail-with-body --silent --show-error \ "$EXECKERNEL_BASE_URL/execkernel/session/next" \ --header "@$OPS_DIR/auth.header" \ --header 'Content-Type: application/json' \ --data "{\"session_id\":\"$SESSION_ID\",\"edge_id\":10}" \ --output "$OPS_DIR/confirmed.json"
python3 -m json.tool "$OPS_DIR/confirmed.json"HTTP 200, state.current_node: 2 and payload.type: "terminal" confirm the accepted choice. That position is the one your application should recover after the service cycle.
Restart and recover the same execution
Section titled “Restart and recover the same execution”Restart the two services, wait for their checks and request the saved session:
ekcompose restart api webekcompose up -d --no-build --pull never --wait
curl --fail-with-body --silent --show-error \ "$EXECKERNEL_BASE_URL/execkernel/session/resume" \ --header "@$OPS_DIR/auth.header" \ --header 'Content-Type: application/json' \ --data "{\"session_id\":\"$SESSION_ID\"}" \ --output "$OPS_DIR/recovered.json"
python3 -m json.tool "$OPS_DIR/recovered.json"The recovered response has the same session_id, node 2 and terminal payload. resume reads the saved position and rebuilds its presentation; it does not take edge 10 again. The database survived because it is in the volume. The token and catalogue still match the running service’s configuration.
A successful health check alone cannot establish that this particular execution is recoverable. An expired session or a changed graph identity can prevent recovery while the service otherwise runs. Keep the known-session check alongside deployment health in your release procedure.
Update the service and preserve a recovery path
Section titled “Update the service and preserve a recovery path”Before replacing a production deployment, take a consistent database backup and restore it in a separate instance using the backup and recovery procedure. That exercise checks the database, matching catalogue and a known session together. Keep the current image IDs, catalogue, configuration and backup as one recovery set.
After selecting the candidate API revision, build its two images under different local tags:
EXECKERNEL_API_IMAGE=execkernel-api:candidate \EXECKERNEL_WEB_IMAGE=execkernel-web:candidate \ ./deploy/build-local.sh ../execkernelBefore replacing the live service, use those candidate image IDs in a separate restoration rehearsal and check its database, health and known session. Change only that rehearsal’s copied environment file while testing. Once the candidate passes, record the old configuration and select the new images for the deployment:
cp "$OPS_DIR/deployment.env" "$OPS_DIR/deployment.previous.env"python3 - <<'PY'import os, subprocessfrom pathlib import Pathp = Path(os.environ["OPS_DIR"]) / "deployment.env"settings = dict(line.split("=", 1) for line in p.read_text().splitlines())for key, tag in [("EXECKERNEL_API_IMAGE", "execkernel-api:candidate"), ("EXECKERNEL_WEB_IMAGE", "execkernel-web:candidate")]: settings[key] = subprocess.check_output( ["docker", "image", "inspect", tag, "--format", "{{.Id}}"], text=True ).strip()p.write_text("".join(f"{key}={value}\n" for key, value in settings.items()))PY
ekcompose up -d --no-build --pull never --waitContainer replacement can interrupt requests. Coordinate the change with your application, and retain known session identifiers so it can resolve any uncertain request outcome.
Startup may apply database migrations. Restoring old images alone is therefore not a general rollback procedure: the database and catalogue must also be compatible. The migration and rollback guide develops this decision: prepare and validate the saved state appropriate to the version you are returning to.
To stop this project while retaining its named session volume:
ekcompose downUse the same project name and configuration when starting it again. Removing the volume, including with down -v, removes the saved database; changing the project name selects another project’s volume.
For remote application access, put the HTTP entry point behind your TLS proxy or encrypted private network. The supplied Nginx service listens for HTTP and does not terminate TLS. Keep FPM private, and apply the token, catalogue and request-limit decisions in API configuration, access and rate limiting.