INTEGRITY Cloudflare Docs

Frequently Asked Questions

How do Container logs work?

To get logs in the Dashboard, including live tailing of logs, toggle observability to true in your Worker's wrangler config:

{
	"observability": {
		"enabled": true
	}
}
[observability]
enabled = true

Logs are subject to the same limits as Worker logs, which means that they are retained for 3 days on Free plans and 7 days on Paid plans.

See Workers Logs Pricing for details on cost.

If you are an Enterprise user, you are able to export container logs via Logpush to your preferred destination.

How are container instance locations selected?

When initially deploying a Container, Cloudflare will select various locations across our network to deploy instances to. These locations will span multiple regions.

When a Container instance is requested with this.ctx.container.start, the nearest free container instance will be selected from the pre-initialized locations. This will likely be in the same region as the external request, but may not be. Once the container instance is running, any future requests will be routed to the initial location.

An Example:

How do container updates and rollouts work?

On wrangler deploy, the Worker goes live first. Container instances update with a gradual rollout by default. Refer to Rollouts for steps, grace periods, and modes. Refer to Deploy Containers to run a deploy.

How do Workers Builds work with Containers?

On the production branch, Workers Builds should run wrangler deploy so images and container instances can update. Non-production Workers Builds defaults to wrangler versions upload, which does not update images. Containers Workers implement Durable Objects, so preview URLs are not generated for them. Refer to Deploy Containers.

How does scaling work?

Containers scale by creating or addressing specific instances. For stateless routing across a fixed number of interchangeable instances, use the getRandom helper.

Refer to scaling and routing for details.

Is built-in autoscaling for stateless applications available?

Not today, though Cloudflare plans to add built-in autoscaling in a future release.

Until then, use getRandom for simple stateless routing and specific instance IDs when you need explicit control over container lifecycle.

What are cold starts? How fast are they?

A cold start is when a container instance is started from a completely stopped state.

If you call env.MY_CONTAINER.get(id) with a completely novel ID and launch this instance for the first time, it will result in a cold start.

This will start the container image from its entrypoint for the first time. Depending on what this entrypoint does, it will take a variable amount of time to start.

Container cold starts can often be in the 1-3 second range, but this is dependent on image size and code execution time, among other factors.

How do I use an existing container image?

Refer to image management.

Is disk persistent? What happens to my disk when my container sleeps?

All disk is ephemeral. When a Container instance goes to sleep, the next time it is started, it will have a fresh disk as defined by its container image.

Snapshots are coming soon, which allow the user to quickly persist and restore the disk from an entire container or a directory.

You can also use FUSE to persist disk to R2 or other object storage backends. Though you should not expect native SSD-like performance while using FUSE.

What happens if I run out of memory?

If you run out of memory, your instance will throw an Out of Memory (OOM) error and will be restarted.

Containers do not use swap memory.

How long can instances run for? What happens when a host server is shut down?

Cloudflare does not stop a container instance after a fixed maximum runtime. The Container class sets sleepAfter to 10 minutes by default, and its default onActivityExpired() implementation signals the container to stop after that period without activity. You can change the duration or override the hook. Even if your hook keeps the instance running, another platform event can stop it. One of those cases is a host server restart, which happens on an irregular cadence. Cloudflare does not guarantee that any container instance will run for any set period of time.

When the platform is about to stop a container instance (including before a host moves work off a server), it:

  1. Sends SIGTERM to the main process in the container.
  2. Waits up to 15 minutes for that process to exit.
  3. Sends SIGKILL if the process is still running.

Handle SIGTERM in your image if you need cleanup before exit. After a host stop, a new container instance may start on a different server when traffic needs it again.

Image updates during a deploy use the same stop sequence. Refer to Rollouts.

How can I pass secrets to my container?

You can use Worker Secrets or the Secrets Store to define secrets for your Workers.

For implementation details, refer to Environment variables and secrets.

Can I run Docker inside a container (Docker-in-Docker)?

Yes. Use the docker:dind-rootless base image since Containers run without root privileges.

You must disable iptables when starting the Docker daemon because Containers do not support iptables manipulation:

Dockerfile
FROM docker:dind-rootless

# Start dockerd with iptables disabled, then run your app
ENTRYPOINT ["sh", "-c", "dockerd-entrypoint.sh dockerd --iptables=false --ip6tables=false & exec /path/to/your-app"]

If your application needs to wait for dockerd to become ready before using Docker, use an entrypoint script instead of the inline command above:

entrypoint.sh
#!/bin/sh
set -eu

# Wait for dockerd to be ready
until docker version >/dev/null 2>&1; do
  sleep 0.2
done

exec /path/to/your-app

For a complete working example, see the Docker-in-Docker Containers example.

How do I allow or disallow egress from my container?

Refer to Handle outbound traffic for how to control outbound traffic and internet access.