GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Guide
  • Examples
  • Log in
  • Sign up

This view

  • Original page
  • New address

GeezerVison is showing modal.com — Named images

Guide Introduction to Modal Getting started Functions Functions Invocation methods Function lookups Container lifecycle management Parametrized Functions Dynamic configuration Sandboxes Sandboxes Running commands Networking and security File access Snapshots Exit Snapshots BetaPricing and resources Sidecars BetaSecret injection BetaModel APIs Model APIs Models and pricing Agent integrations Endpoints Endpoints Supported models Candidates Training Quickstart Tinker-compatible API BetaMulti-node training Images Defining Images Using existing container images Named images Fast pull from registry GPUs and other resources GPU acceleration Using CUDA on Modal Configuring CPU, memory, and disk Scaling out Scaling out Input concurrency Batch processing Job queues Dynamic batching Multi-node Clusters Deployment Apps, Functions, and entrypoints Managing deployments Continuous deployment Scheduled Functions Observability HTTP Applications Servers Sticky Sessions Web Functions Streaming endpoints Web Function URLs Request timeouts Proxy Tokens Networking Tunnels Proxies BetaCluster networking Data sharing and storage Passing local data Volumes Storing model weights Cloud bucket mounts Dicts Queues Dataset ingestion Secrets and environment variables Secrets Environment variables Performance Cold start performance Memory Snapshots High-performance LLM inference Reliability and robustness Failures and retries Preemption Timeouts GPU health Troubleshooting Security and privacy Security and privacy Data residency Customer-supplied encryption keys AlphaAudit logs Integrations Using OIDC to authenticate with external services Connecting Modal to your Datadog account Connecting Modal to your OpenTelemetry provider Slack notifications Workspace & account settings Workspaces Environments Service users User groups Role-Based Access Control (RBAC) Billing Network egress billing Budgets Identity and provisioning Okta SSO Microsoft Entra SSO Google Workspace SSO Custom SAML SSO SCIM Integration Other topics Feature maturity Restricted Functions JavaScript/Go SDKs BetaModal 1.0 migration guide File and project structure Developing and debugging Jupyter notebooks Asynchronous API usage Global variables Region selection Localized placement GPU Metrics Search syntax

Named images

Named Images let you publish a Modal Image under a name that you can reference later to use the Image, akin to a container registry.

This can be useful for stricter Image change management and for avoiding unintended Image invalidation and rebuilds on latency-sensitive code paths.

Unlike inline Image definitions, referencing an image by name will never implicitly rebuild an Image. The Image reference for a name is mutable, and because the reference is typically updated only after a successful publish, callers keep using the previous working Image while the new build is running.

A typical workflow using named images would be:

  1. Define, build, and publish the Image in an independently run Image build script
  2. Reference the published Image by name in Sandbox or Function code, getting the latest build of that image at the time

Publishing an Image from a script 

Use Image.build to build the Image, then call .publish() on the resulting Image:

# build_image.py
app = modal.App.lookup("image-builds", create_if_missing=True)

image = (
    modal.Image.debian_slim(python_version="3.12")
    .apt_install("git")
    .uv_pip_install("numpy", "pandas", "scikit-learn")
    .run_commands("python -c 'import sklearn; print(sklearn.__version__)'")
)

with modal.enable_output():
    image.build(app).publish("analytics-runtime")
// build_image.ts
const app = await modal.apps.fromName("image-builds", {
  createIfMissing: true,
});

const image = modal.images
  .fromRegistry("python:3.12-slim")
  .dockerfileCommands([
    "RUN apt-get update && apt-get install -y git",
    "RUN pip install numpy pandas scikit-learn",
    "RUN python -c 'import sklearn; print(sklearn.__version__)'",
  ]);

const builtImage = await image.build(app);
await builtImage.publish("analytics-runtime");
// build_image.go
app, err := mc.Apps.FromName(ctx, "image-builds", &modal.AppFromNameParams{
	CreateIfMissing: true,
})

image := mc.Images.FromRegistry("python:3.12-slim", nil).
	DockerfileCommands([]string{
		"RUN apt-get update && apt-get install -y git",
		"RUN pip install numpy pandas scikit-learn",
		"RUN python -c 'import sklearn; print(sklearn.__version__)'",
	}, nil)

builtImage, err := image.Build(ctx, app, nil)
err = builtImage.Publish(ctx, "analytics-runtime", nil)

Starting Sandboxes using named Images 

Named Images are especially useful for Sandboxes because Sandbox creation often happens on a latency-sensitive path and you typically never want to block Sandbox creation on rebuilding an Image.

Use Image.from_name when referencing a named Image that you have previously built, and start the Sandbox using that:

# sandbox_launcher.py
sb = modal.Sandbox.create(
    "python",
    "-c",
    "import pandas, sklearn; print('ready')",
    # prefer named Images in Sandboxes to ensure they are never built during Sandbox launch
    image=modal.Image.from_name("analytics-runtime"),
    app=app,
)
print(sb.stdout.read())
// sandbox_launcher.ts
// prefer named Images in Sandboxes to ensure they are never built during Sandbox launch
const image = await modal.images.fromName("analytics-runtime");
const sb = await modal.sandboxes.create(app, image);

const p = await sb.exec([
  "python",
  "-c",
  "import pandas, sklearn; print('ready')",
]);
console.log(await p.stdout.readText());
// sandbox_launcher.go
// prefer named Images in Sandboxes to ensure they are never built during Sandbox launch
image, err := mc.Images.FromName(ctx, "analytics-runtime", nil)
sb, err := mc.Sandboxes.Create(ctx, app, image, nil)

p, err := sb.Exec(ctx, []string{
	"python",
	"-c",
	"import pandas, sklearn; print('ready')",
}, nil)
stdout, err := io.ReadAll(p.Stdout)
fmt.Println(string(stdout))

Running Functions using named Images 

Named Images can also be used when defining Modal Functions when you want more control over when a Function starts using a new Image. To use a named Image, point the Function image attribute to a Image.from_name reference:

# app.py
@app.function(image=modal.Image.from_name("analytics-runtime"))
def train():
    import pandas as pd
    from sklearn.linear_model import LinearRegression
    ...

Note that publishing a new version of this named Image would not automatically update your deployed Functions to use the updated Image. You still need to redeploy the App that references that name for the change to propagate.

Tags 

Every named Image is represented using a {name}:{tag} name - if you do not specify the tag part, the :latest tag is automatically used. You can publish the same Image using multiple names or tag which can be useful to do things like versioning of images.

Named imagesPublishing an Image from a scriptStarting Sandboxes using named ImagesRunning Functions using named ImagesTags
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.