Docker Deployment
NL2SQL can be deployed as a standalone HTTP service using the nl2sql-api package and Docker. You can also embed the core library in your own service.
For a ready-made stack (one service, one volume, API keys on), see Docker Compose.
For the web app served as a public demo of the sample databases, where each visitor brings their own API key, see Hosted demo.
Container requirements
- Install
nl2sql-engineand add adapters via extras (e.g.nl2sql-engine[postgres]). The repository'sDockerfilealso installsnl2sql-cli, sodocker compose run --rm api nl2sql indexworks in the image. - Provide the config:
nl2sql.yamland the files it includes, at the pathNL2SQL_CONFIGnames. TheDockerfileat the repository root setsNL2SQL_CONFIG=/etc/nl2sql/nl2sql.yaml, so mount a config folder there. - Provide the provider keys and any variable the config reads as
${env:VAR}, in the environment or in a.envnext tonl2sql.yaml(loaded bynl2sql-api serve, the image's command, never overriding a variable already set, and never when hosted; plain uvicorn does not load it).
Persistence mounts
Everything the engine writes lives under storage.path: the vector index
(index/), the state store (state.db: schema snapshots, the plan cache and
feedback), run traces (traces/) and result files (results/). Mount one
volume and point storage.path at it, typically from the environment:
docker run --rm -p 8000:8000 \
-v "$PWD/config:/etc/nl2sql:ro" \
-v nl2sql-data:/data -e NL2SQL_DATA_DIR=/data \
-e OPENAI_API_KEY \
nl2sql-api
See Storage.
Startup
The API builds the engine from the config and calls engine.check() before it
accepts a request. A datasource with required: true that cannot connect stops
the container (EngineNotReady in the log); any other one that fails is logged
and left out of routing. Mark the datasources the service cannot run without
required: true, so the orchestrator restarts a container that started broken.
API roles
nl2sql-api identifies callers from api.auth (api_keys, proxy, static
or none), and policies.admin_roles (default [admin]) says which roles may
change datasources, LLMs and the index. The image binds 0.0.0.0, and
serve refuses to start under the default none, so set api.auth for a
container, for example api_keys:
Create keys with nl2sql keys create. See
API settings,
Identity and
Admin routes.
Notes
- Schema indexing is not automatic; you must run indexing in your operational
flow:
nl2sql --config /etc/nl2sql/nl2sql.yaml indexagainst the same storage, orPOST /api/v1/jobs/index(admin role). - Observability exporters require network access. They are observers in the
config's
observerssection: anotelobserver with itsendpoint(the API image installs theotelextra; see Observers).NL2SQL_LOG_FORMAT=jsongives JSON log lines. Theauditobserver writes understorage.path, so mount that volume to keep the audit log.
Reference configuration
See Configuration for the whole config and the environment variables it reads.