Infrastructure¶
The latent infra command manages local development infrastructure via Docker Compose. It provisions three services that back the Latent evaluation workflow: PostgreSQL, Prefect server, and MLflow tracking server.
Overview¶
| Service | Purpose | Default Port |
|---|---|---|
| PostgreSQL | Shared database for Prefect and MLflow | 5432 |
| Prefect | Workflow orchestration server and UI | 4200 |
| MLflow | Experiment tracking server and UI | 5001 |
All three services are defined in a single docker-compose.yaml at the repository root. PostgreSQL acts as the backing store for both Prefect (workflow state) and MLflow (experiment metadata).
When latent infra up starts successfully, it writes a state file to .latent/infra/state.json in the workspace. Other commands -- notably latent run -- read this file to auto-configure PREFECT_API_URL and MLFLOW_TRACKING_URI so flows connect to the local services without manual environment setup.
Prerequisites¶
- Docker with Compose v2 (
docker compose) or the standalonedocker-composebinary. - Ports 5432, 4200, and 5001 available (or overridden via environment variables).
Commands¶
latent infra up¶
Start infrastructure services.
# Start all services in the foreground (streams Docker logs, Ctrl-C to stop)
latent infra up
# Start in background (detached)
latent infra up --detach
latent infra up -d
# Start specific services only
latent infra up postgres prefect
| Flag | Description |
|---|---|
--detach, -d |
Run in background. Uses --wait to block until services are healthy. |
Available service names: postgres, prefect, mlflow.
When running in the foreground, pressing Ctrl-C triggers latent infra down automatically.
latent infra down¶
Stop all infrastructure services and remove containers.
# Stop services, keep data volumes
latent infra down
# Stop services and delete persistent data (PostgreSQL data, etc.)
latent infra down --volumes
latent infra down -v
| Flag | Description |
|---|---|
--volumes, -v |
Also remove persistent Docker volumes (destroys database data). |
latent infra status¶
Show a table of running service names, health status, and exposed ports.
Example output:
Infrastructure Status
+----------+---------+-------+
| Service | Status | Ports |
+----------+---------+-------+
| postgres | healthy | 5432 |
| prefect | healthy | 4200 |
| mlflow | healthy | 5001 |
+----------+---------+-------+
If no services are running, the command prints a hint to run latent infra up.
latent infra logs¶
Show logs for infrastructure services.
# Show last 50 lines from all services
latent infra logs
# Follow logs in real time
latent infra logs --follow
latent infra logs -f
# Show logs for a specific service
latent infra logs prefect
# Control number of lines
latent infra logs --lines 200
latent infra logs -n 200
| Flag | Description |
|---|---|
--follow, -f |
Tail logs in real time (Ctrl-C to stop). |
--lines, -n |
Number of historical lines to show (default: 50). |
latent infra env¶
Print shell export statements for connecting to the running infrastructure. Designed to be used with eval:
Output:
export PREFECT_API_URL="http://localhost:4200/api"
export MLFLOW_TRACKING_URI="http://localhost:5001"
Note
latent run reads the infra state file automatically, so you typically do not need to run eval $(latent infra env) unless you are using Prefect or MLflow CLIs directly.
Configuration¶
Environment Variables¶
Override default ports by setting these variables before running latent infra up:
| Variable | Default | Description |
|---|---|---|
LATENT_INFRA_PG_PORT |
5432 |
Host port for PostgreSQL |
LATENT_INFRA_PREFECT_PORT |
4200 |
Host port for the Prefect server and UI |
LATENT_INFRA_MLFLOW_PORT |
5001 |
Host port for the MLflow tracking server and UI |
Example:
Docker Compose File¶
The docker-compose.yaml at the repository root defines the services:
- postgres --
postgres:16-alpinewith alatentuser/database. An init script atinfra/init-databases.sqlcreates additional databases required by Prefect and MLflow. Data is persisted in a Docker volume (latent-pgdata). - prefect -- Built from
infra/Dockerfile.prefect. Connects to PostgreSQL viapostgresql+asyncpg. Depends on a healthypostgrescontainer. - mlflow -- Built from
infra/Dockerfile.mlflow. Also depends on a healthypostgrescontainer.
State File¶
When services start, InfraManager writes .latent/infra/state.json in the workspace:
{
"prefect_api_url": "http://localhost:4200/api",
"mlflow_tracking_uri": "http://localhost:5001",
"pg_port": 5432
}
This file is removed on latent infra down. Other Latent commands use it to auto-configure connections.
Typical Workflow¶
# 1. Start infrastructure in the background
latent infra up -d
# 2. Verify services are healthy
latent infra status
# 3. Run a flow (auto-connects to Prefect and MLflow)
latent run my_eval_flow
# 4. View results in the MLflow UI
open http://localhost:5001
# 5. Stop when done
latent infra down
See Also¶
- CLI Tools - Full CLI reference
- MLflow Tracking - MLflow integration details
- Workspace Configuration - Environment variables and config files