> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datazone.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Containers

> Run your own long-running services — model servers, APIs, web tools — next to your data

A **Container** is a long-running service that Datazone builds and runs for your project. You declare it in `config.yml`, either as a `Dockerfile` in the repository or as an existing image, and Datazone runs it on your deployment's cluster.

Use a container when a pipeline or action needs something that has to stay up between calls:

* **Model servers** — an embedding or image model loaded once and called many times (for example a CLIP server that fills an [Empty Vector](https://docs.datazone.co/reference/development/vectors.md#empty-vectors))
* **Internal APIs** — a service in any language that your actions and pipelines call
* **Web tools** — a small web UI or API for the people in your organisation, or for anyone with the link

## How it works

1. **Declare the container** under `containers:` in `config.yml` and push. Datazone registers it on that branch. Registering **does not** deploy it.
2. **Deploy.** Open **Containers** in the project and click **Deploy**. Datazone builds the image from the branch's latest commit (or pulls the image you named) and starts it.
3. **Call it.** Actions and pipelines call it with [`ContainerAPI`](#calling-a-container-from-code). `authenticated` and `public` containers also get a URL.
4. **Stop it** when you don't need it. A stopped container uses no compute.

Each branch deploys separately. A container on `feature-x` runs the code and config of `feature-x`, at its own URL, without touching `main`. Only one deployment per branch runs at a time, and by default at most two branches of a container run at once.

## Declaring a container

```yaml config.yml theme={null}
containers:
  # Built from a Dockerfile in the repository
  - alias: clip-embedder
    name: CLIP Embedder
    path: containers/clip
    port: 8000
    compute: SMALL
    healthcheck_path: /health
    files:
      - source: models/clip
        target: weights

  # Run from an existing image
  - alias: whoami
    image: traefik/whoami:v1.10
    port: 80
    access: public
```

**alias** `string` *required*

Identifies the container in the project. Lowercase letters, digits and hyphens, starting and ending with a letter or digit, at most 40 characters. Unique within the project. `ContainerAPI` uses it to find the container.

**name** `string`

Display name. Defaults to the alias.

**path** `string`

Folder in the repository that holds the `Dockerfile`. It is the build context. Set exactly one of `path` or `image`.

**dockerfile** `string` (default: Dockerfile)

Name of the Dockerfile inside `path`.

**image** `string`

An existing image to run instead of building one, for example `traefik/whoami:v1.10`. Datazone pulls it without credentials, so it must be in a public registry. Pin a tag; `latest` can change between deployments.

**files** `array`

Folders copied from the project's [File Container](https://docs.datazone.co/reference/development/file-container.md) into the build context before the build. Use it for files too large for git, such as model weights. Only for containers built from a `path`.

* **`source`** — folder in the file container
* **`target`** — folder in the build context, relative to `path`

Both must be relative paths. The Dockerfile then copies them like any other file: `COPY weights/ /app/weights/`.

**port** `integer` *required*

The port the service listens on inside the container.

**replicas** `integer` (default: 1)

Number of copies to run. Requests are spread across them. At most 3 by default.

**compute** `string` (default: 2XSMALL)

Size of each replica. See [Compute sizes](#compute-sizes).

**access** `string` (default: internal)

Who can call the container: `internal`, `authenticated` or `public`. See [Access levels](#access-levels).

**healthcheck\_path** `string`

An HTTP path that answers `2xx` when the service is ready, for example `/health`. When set, Datazone sends traffic to a replica only after the path answers, and restarts a replica that stops answering. Without it, a replica gets traffic as soon as its process starts.

If a container's entry can't be deployed, for example because its Dockerfile is missing or it asks for too many replicas, the container page shows why. Fix the entry and push again.

## Compute sizes

Each replica gets the full CPU and memory of its size for as long as it runs.

| Compute | vCPU | Memory |
| - | - | - |
| `2XSMALL` (default) | 1 | 4 GB |
| `XSMALL` | 2 | 8 GB |
| `SMALL` | 4 | 16 GB |
| `MEDIUM` | 8 | 32 GB |
| `LARGE` | 8 | 64 GB |
| `XLARGE` | 16 | 128 GB |

Running containers use compute (DCU) for every replica, for every minute they run. A stopped container uses none.

## Access levels

| Access | Who can call it | URL |
| - | - | - |
| `internal` (default) | Only actions and pipelines of the same project, with `ContainerAPI` | None |
| `authenticated` | Members of your organisation who can read the container, with an [API key](https://docs.datazone.co/reference/development/api-key.md) | Yes |
| `public` | Anyone with the URL | Yes |

Actions and pipelines of the project can call a container at any access level.

> [!WARNING]
>
> A `public` container is open to the internet. Anyone with its URL can call it. Use `authenticated` unless the service is meant to be open.

## Deploying and stopping

On the container's page, pick the branch and click **Deploy**. The deployment goes through these statuses:

| Status | Meaning |
| - | - |
| `QUEUED` | Waiting to start |
| `BUILDING` | Building the image from the `Dockerfile` (skipped for `image` containers) |
| `DEPLOYING` | Starting the replicas and waiting for them to be ready |
| `RUNNING` | Serving requests |
| `STOPPED` | Stopped by a user |
| `ERROR` | The build or the start failed; the error message says why |
| `TIMEOUT` | The replicas didn't become ready within 10 minutes |

The **Deployments** tab lists every deployment with its commit, status and build log. If a deploy fails, the container that was already running keeps running.

A new deploy replaces the running one when it is ready. To pick up a new commit, a changed `config.yml` entry or changed environment variables, deploy again.

**Stop** scales the branch down to zero. Deploy again to start it.

## Environment variables

Set environment variables on the **Environment** tab:

* **Shared** variables apply to every branch.
* **Branch overrides** replace a shared variable with the same name on one branch.
* Mark a value as **secret** to store it encrypted. A secret is never shown again after you save it.

Changes take effect on the next deploy.

A container gets no Datazone credentials of its own. If it needs to call the Datazone API, create an [API key](https://docs.datazone.co/reference/development/api-key.md) and add it as a secret variable.

## Organisation overview

**Settings → Containers** lists every container pod running in your organisation, across all projects, like an activity monitor. You need the `compute:manage` permission to see it. See [Policies](https://docs.datazone.co/reference/development/policy.md#manage-permissions-and-settings-access).

Each row is one pod (one replica), read from the cluster:

| Column | Shows |
| - | - |
| **Pod** | The pod's name |
| **Container** | The container, with its project and branch |
| **Status** | The pod's state, for example `Running` or `CrashLoopBackOff` |
| **Ready** | Whether the pod passes its health check |
| **Restarts** | How many times the pod has restarted |
| **CPU** / **Memory** | What the pod uses now, and how much of one replica's compute size that is |
| **Node** | The cluster node the pod runs on |
| **Started** | When the pod started |

The list refreshes every 10 seconds. A pod whose container was deleted is shown as **Container removed**.

Click a pod to open its container branch:

* **Overview** — the image, commit, compute, ready replicas, access, port and URL, and a **Usage** chart of CPU and memory for all replicas together, against the limit they reserve. Pick the last hour, 6 hours, 24 hours or 7 days.
* **Pods & Events** — each replica with its node and IP, and the Kubernetes events of the deployment and its pods. The cluster keeps events for about an hour.
* **Deployments** — every deployment with its build log.
* **Environment** — the variables the next deployment gets: shared variables and this branch's overrides. Secret values stay hidden.

**Open in project** goes to the container's page in its project. **Stop** scales the branch down to zero; you need write access to the project.

## Calling a container

### From actions and pipelines

`ContainerAPI` calls a container of the same project by its alias. It signs in with the run's access key, so it works at every access level, including `internal`.

```python theme={null}
from datazone import ContainerAPI, Dataset, Input, transform  # in an action: from datazone.actions import ContainerAPI

@transform(input_mapping={"captions": Input(Dataset(alias="captions"))}, engine="pandas")
def embed_captions(captions):
    embedder = ContainerAPI("clip-embedder")
    response = embedder.post("/embed/text", json={"texts": captions["caption"].tolist()})
    response.raise_for_status()
    return captions.assign(embedding=response.json()["embeddings"])
```

**ContainerAPI** `class`

Parameters:

* **`alias`** — the container's alias in `config.yml`
* **`branch`** *(optional)* — the branch whose deployment is called. Default: `main`.
* **`timeout`** *(optional)* — default request timeout in seconds. Default: `300`.

Methods: **`get`**, **`post`**, **`put`**, **`patch`**, **`delete`** and **`request(method, path)`**. Each takes a path inside the container and the same keyword arguments as `requests` (`json`, `params`, `data`, `headers`, ...), and returns a `requests.Response`.

If the container doesn't exist or isn't running on that branch, `ContainerAPI` raises an error that says so, for example `Container 'clip-embedder' on branch 'main' cannot be called: Container not found.`

### With its URL

`authenticated` and `public` containers are served at:

```
https://<your-datazone-host>/api/v1/container-proxy/<container-slug>/<branch-slug>/<path>
```

The container's **Overview** tab shows the URL, an **Open URL** button, and ready-to-copy `curl`, Python and JavaScript examples. For an `authenticated` container, send an API key in the `x-api-key` header. Your Datazone browser session is not accepted, so a web UI meant for people in a browser must be `public`.

```bash theme={null}
curl "https://<your-datazone-host>/api/v1/container-proxy/<container-slug>/main/health" \
  -H "x-api-key: <YOUR_API_KEY>"
```

The container receives the request at `/<path>`, without the `/api/v1/container-proxy/...` prefix. A web UI served this way must use relative links (`./assets/app.js`, not `/assets/app.js`), because its pages are under that prefix.

Datazone removes your credentials (`Authorization`, `x-api-key`, cookies) before the request reaches the container, and drops any cookie the container tries to set. A request waits at most 5 minutes for the container to start answering.

## Security

* Containers run as a non-root user (uid `10001`) with all Linux capabilities dropped. Build your image so it works as a non-root user: don't write to root-owned folders at runtime.
* Images are built in an isolated build job with rootless BuildKit.
* A container accepts traffic only from the Datazone proxy and your organisation's pipelines. It can reach the public internet, but not other services inside the cluster.
* Environment variables are stored in a Kubernetes Secret, not in the pod spec. Secret values are encrypted in Datazone.

## Example: an embedding server

A small FastAPI service that loads a model once and embeds text on request.

```dockerfile containers/clip/Dockerfile theme={null}
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY weights/ ./weights/
COPY server.py .
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8000"]
```

```python containers/clip/server.py theme={null}
from fastapi import FastAPI
from sentence_transformers import SentenceTransformer

app = FastAPI()
model = SentenceTransformer("./weights")


@app.get("/health")
def health():
    return {"ok": True}


@app.post("/embed/text")
def embed(body: dict):
    return {"embeddings": model.encode(body["texts"]).tolist()}
```

An action that embeds a query with it and searches an [Empty Vector](https://docs.datazone.co/reference/development/vectors.md#empty-vectors):

```python theme={null}
from datazone.actions import action, ContainerAPI, Vector

@action
def search_images(query: str):
    response = ContainerAPI("clip-embedder").post("/embed/text", json={"texts": [query]})
    response.raise_for_status()
    embedding = response.json()["embeddings"][0]
    return Vector("dog-images").search(vector=embedding, limit=5)
```

## Next steps

* [Vectors](https://docs.datazone.co/reference/development/vectors.md#empty-vectors) — store the embeddings your container produces
* [Actions](https://docs.datazone.co/reference/development/actions.md#containerapi) — call containers from actions
* [Project configuration](https://docs.datazone.co/reference/development/project.md) — the rest of `config.yml`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.