Skip to main content

Container

Deploy and manage container applications on Cloudflare’s global network.

Container Binding

Creates a Container binding for use in Cloudflare Workers.

Props

className
string
required
The class name for the container binding.
const container = await Container("my-container", {
  className: "MyContainerClass",
  build: {
    context: "./docker/container"
  }
});
build
object
Docker build configuration.
image
string
Pre-built image reference (alternative to build).
maxInstances
number
default:"10"
Maximum number of container instances that can be running.
instanceType
InstanceType
default:"dev"
Instance type determining compute resources.Options: lite, dev, basic, standard, standard-1, standard-2, standard-3, standard-4

Output

id
string
Unique identifier for the container.
className
string
Class name used to identify the container in Worker bindings.
image
Image
Docker image configuration for the container.
type
container
Type identifier for the binding.

Example

const container = await Container("my-container", {
  className: "MyContainerClass",
  build: {
    context: "./docker/container"
  },
  maxInstances: 100
});

const worker = await Worker("my-worker", {
  entrypoint: "./src/worker.ts",
  bindings: {
    MY_CONTAINER: container
  }
});

ContainerApplication

Deploy a managed container application with automatic scaling.

Props

name
string
The name of the container application.
image
Image
required
The Docker image to deploy in the container application.
instances
number
default:"1"
The initial number of container instances to deploy.
maxInstances
number
default:"1"
The maximum number of instances to be used for the deployment.
instanceType
InstanceType
default:"dev"
The instance type to be used for the deployment.
Instance TypevCPUMemory (Min)Memory (Max)
lite1/16256 MiB2 GB
basic1/41 GiB4 GB
standard-11/24 GiB8 GB
standard-216 GiB12 GB
standard-328 GiB16 GB
standard-4412 GiB20 GB
schedulingPolicy
SchedulingPolicy
default:"default"
Scheduling policy that controls container placement.Options: moon, gpu, regional, fill_metals, default
rollout
ContainerApplicationRollout
Configuration for progressive rollout when updating.
adopt
boolean
default:"false"
Whether to adopt an existing container application with the same name.

Output

id
string
Unique identifier for the container application.
name
string
Human-readable name of the container application.

Examples

Simple Web Application

const webApp = await ContainerApplication("my-web-app", {
  name: "my-web-app",
  image: await Image("web-app", {
    name: "web-app",
    build: {
      context: "./docker/web-app"
    }
  }),
  instances: 1,
  maxInstances: 3
});

GPU-Enabled AI Application

const aiApp = await ContainerApplication("ai-inference", {
  name: "ai-inference",
  image: await Image("ai-model", {
    name: "ai-model",
    build: {
      context: "./docker/ai"
    }
  }),
  schedulingPolicy: "gpu",
  instances: 2,
  maxInstances: 5
});

Container with Durable Objects

const doNamespace = DurableObjectNamespace("my-do", {
  className: "MyDO"
});

const worker = await Worker("do-worker", {
  entrypoint: "./src/worker.ts",
  bindings: {
    DO: doNamespace
  }
});

const containerApp = await ContainerApplication("stateful-app", {
  name: "stateful-app",
  image: await Image("do-app", {
    name: "do-app",
    build: {
      context: "./container"
    }
  }),
  durableObjects: {
    namespaceId: doNamespace.namespaceId
  },
  instances: 1,
  maxInstances: 10
});

Progressive Rollout

const app = await ContainerApplication("my-app", {
  image: await Image("app", {
    build: { context: "./docker" }
  }),
  instances: 10,
  maxInstances: 20,
  rollout: {
    strategy: "rolling",
    stepPercentage: 10  // Update 10% at a time
  }
});

Build docs developers (and LLMs) love