Container images

Build the environment your task runs in with a fluent, immutable chain.

Image builder

Every method returns a new Image — the chain is immutable. Steps are executed top-to-bottom at deploy time, and each unique chain is cached by its content hash.

python
1image = (2    gw.Image.base("python:3.12-slim")3        .pip_install("torch==2.3.0", "transformers", "accelerate")4        .system_install("ffmpeg", "libsndfile1")5        .env(HF_HOME="/data/hf", TOKENIZERS_PARALLELISM="false")6        .workdir("/app")7)

Attach to a task

Pass the image to @app.task or @app.cls. Multiple tasks can share the same image object — the build layer is reused.

python
1@app.task(image=image, gpu=gw.Gpu("H100"))2async def generate(prompt: str) -> str:3    from transformers import pipeline4    pipe = pipeline("text-generation", model="gpt2")5    return pipe(prompt)[0]["generated_text"]

Install from requirements.txt

Read packages from a requirements file at deploy time. The path is relative to the project root.

python
1image = (2    gw.Image.base("python:3.12-slim")3        .pip_install_requirements("requirements.txt")4)

Add local files

Bundle a local directory or file into the image. Useful for model configs, data files, or private packages not on PyPI.

python
1image = (2    gw.Image.base("python:3.12-slim")3        .add_local_dir("./configs", "/app/configs")4        .add_local_file("./tokenizer.json", "/app/tokenizer.json")5)

Raw Dockerfile commands

Escape hatch for directives not covered by the builder API.

python
1image = (2    gw.Image.base("nvidia/cuda:12.3.0-runtime-ubuntu22.04")3        .dockerfile_commands("LABEL [email protected]")4        .run_commands("apt-get update && apt-get install -y curl")5)