使用 Cloudflare Containers 部署容器应用




English version: Deploy Containers with Cloudflare Container – Frank’s Weblog

今天(2025/6/24),Cloudflare 宣布推出 Cloudflare Containers:其在 Cloudflare Workers 中的无服务器容器运行时。Cloudflare Containers 目前处于公开测试阶段,所有 Cloudflare Worker 的付费用户都可以使用。

作为一名容器爱好者,我花了一些时间探索该产品。我将以 httpbin 为例,说明如何将一个简单的应用程序部署到 Cloudflare Containers。

先决条件

  • Nodejs
  • wrangler (Cloudflare worker 命令行工具)
  • Docker
  • Cloudflare Workers 付费计划

代码

你需要的所有代码都在这里: https://github.com/frankgx97/httpbin-cfcontainers

src/index.ts 是应用程序的入口点,它将请求路由到容器。

wrangler.jsonc 是 Cloudflare Worker 应用程序的定义文件,我们在其中定义应用程序、容器和持久对象。

部署

在部署之前,我们需要准备镜像。

Cloudflare Containers 仅支持 Cloudflare Image Registry。你可以在部署应用程序时通过指定 "image": "./Dockerfile" 来构建和发布镜像,或者,在本例中,将现有镜像推送到 Cloudflare Registry。

假设镜像已在本地存在,请先 tag 镜像。

docker tag kennethreitz/httpbin httpbin:1

请注意,镜像必须有标签,并且不能是 latest

wrangler containers push httpbin:1

你将获得格式为 registry.cloudflare.com/(随机字符串)/httpbin:1 的新镜像标签。

将新的镜像标签填入 wrangler.jsonc

然后运行 wrangler deploy

访问 wrangler 返回的链接,你应该能看到已部署的应用程序。

References

  1. https://github.com/megaconfidence/wifski
  2. Cloudflare Containers 101 – Run Docker Containers on the Edge – YouTube
  3. Containers are available in public beta for simple, global, and programmable compute



Posted

in

by

Comments

发表回复/Leave a Reply

您的电子邮箱地址不会被公开。/Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.