この紹介文は現在英語版のみです。
Cloudflare Containers are a new offering designed to supercharge applications built on Cloudflare Workers by allowing you to run Docker containers directly on the edge.
Summary of the video content
-
What are Cloudflare Containers?
- They enable you to run applications that require more resources than traditional Workers, such as those needing a full file system, custom environments, or specific programming languages not natively supported by Workers.
- They support heavy compute, different languages like Go, Rust, or Ruby on Rails, and even legacy binaries.
- Unlike standard Workers, containers provide a complete file system and support multi-threading.
- Containers can automatically shut down after a period of inactivity (e.g., 5 minutes after a request) to manage resource usage.
- They integrate seamlessly with other Cloudflare developer tools like KV store, D1 database, R2, and Workers AI because they leverage Workers and Durable Objects.
-
Real-World Demonstrations:
- Full Linux Desktop on the Edge: A demonstration showed a complete Debian 11 Linux desktop environment with an XFCE GUI running inside a Cloudflare Container. Users could open a terminal, check the OS version, install applications like GIMP, and even browse the internet with Firefox, including watching YouTube videos, all streamed from the edge.
- Video to GIF Conversion with Whipsky: The “Whipsky” project was presented, which converts videos to GIFs directly in the browser. This application runs an FFmpeg binary (which cannot run on a standard Cloudflare Worker) within a Rust server inside a container. The process involves the Worker receiving the video upload, forwarding it to a container instance, the container processing it with FFmpeg, and then returning the GIF to the Worker for delivery to the browser.
-
Getting Started Requirements:
- All necessary tools are free of charge.
- You need a Cloudflare account (free to sign up at
dash.cloudflare.com, no credit card required). - Node.js must be installed on your local machine.
- Docker must be installed locally, as containers are built with Docker and then pushed to the Cloudflare image registry for deployment.
-
Deploying Your First Container (Whipsky Walkthrough):
- The deployment process typically involves cloning a GitHub repository, installing dependencies, and running a deployment command (e.g.,
npm run deploy). - Docker build process: The deployment command triggers a local Docker build, installing language-specific dependencies (like Rust dependencies with Cargo). Temporarily turning off your VPN might prevent SSL issues during this build.
Wrangler.jsonconfiguration: This file defines the container’s configuration, including its name, Docker image reference, hardware configuration (e.g., 4 GB disk space, 2 GB RAM, 2 CPU cores), and the maximum number of container instances (e.g., up to three for stateless load balancing).Dockerfilestructure: This file outlines how the container is built, specifying dependencies (like Rust and FFmpeg), exposed ports (e.g., 8080 for the Rust server), and the entry point command for the application.- Worker-Container Interaction: The Cloudflare Worker acts as the entry point, receiving requests and forwarding them to an available container instance. Containers are often set up as Durable Objects, allowing the Worker to interact with them, specify the running port, and define how long the container should remain active after a request (
sleepAfter). You can override methods likeonStart,onStop,onError, andonConnectionfor granular control and logging.
- The deployment process typically involves cloning a GitHub repository, installing dependencies, and running a deployment command (e.g.,
-
Monitoring with the Cloudflare Dashboard:
- The dashboard provides metrics and stats on resource consumption (disk space, RAM, CPU cores).
- You can see all instances of your container, noting whether they are active or inactive.
- A “logs” tab displays real-time standard output from your container with timestamps, which is useful for debugging.
- The dashboard also shows linked resources like the associated Cloudflare Worker and Durable Object, providing complete visibility into their metrics and status.
-
Future Developments:
- Cloudflare is continuously enhancing its Container offering.
- Future features include autoscaling and logging colocation, among other planned enhancements.
