Oxcart 下载
菜单

在 Mac 上本地运行和测试 Google Cloud Run 容器

要在 Apple 芯片 Mac 上测试 Cloud Run 服务,请为 linux/amd64 构建镜像,并设置 PORT 变量后运行:docker run -e PORT=8080 -p 8080:8080 IMAGE。在 Oxcart 上,我们自己的服务和 Google 的 Cloud Run 示例都能这样运行,amd64 镜像通过 Rosetta 执行,因此测试的就是最终部署的同一个镜像。

更新于

Cloud Run 的容器运行约定

Cloud Run 可以运行任何符合几条基本约定的容器。Google 文档说明,请求默认发送到端口 8080,PORT 环境变量会设置在入口容器上,容器“必须在 0.0.0.0 上监听请求”,且“不应在 127.0.0.1 上监听”。文档还说明 Cloud Run“明确支持 Linux x86_64 ABI 格式”,多架构镜像必须包含 linux/amd64。

其中两条容易让 Mac 开发者踩坑:绑定 localhost 的应用在本地终端中正常,却会在 Cloud Run 上失败;而在 Apple 芯片 上原生构建的镜像是 arm64。在本地测试实际容器,可以在部署前发现这两个问题。

在 Apple 芯片 上本地测试 Cloud Run 服务

  1. 在 $PORT 和 0.0.0.0 上监听。 让服务器读取 PORT 环境变量(Cloud Run 默认向 8080 发送请求),并绑定 0.0.0.0,而非 127.0.0.1。
  2. 为 linux/amd64 构建。 运行 docker buildx build --platform linux/amd64 --load -t my-service .。Cloud Run 支持 Linux x86_64 ABI,因此在 Mac 上原生构建的 arm64 镜像目标架构不符。
  3. 按 Cloud Run 的方式运行。 运行 docker run --rm --platform linux/amd64 -e PORT=8080 -p 8080:8080 my-service。Oxcart 通过 Rosetta 运行 amd64 镜像。
  4. 调用服务。 运行 curl localhost:8080。要检查 PORT 的处理方式,请用 -e PORT=9090 -p 9090:9090 启动第二个实例。
  5. 推送到 Artifact Registry。 执行一次 gcloud auth configure-docker REGION-docker.pkg.dev,然后将镜像标记为 REGION-docker.pkg.dev/PROJECT/REPO/my-service:TAG,再用 docker push 推送。

我们在 Oxcart 上运行了什么

一个绑定 $PORT 的小型 Python 服务,分别使用不同端口运行两次,再加上 Google 自己的示例镜像:

docker run -d -e PORT=8080 -p 18081:8080 my-service
docker run -d -e PORT=9090 -p 18090:9090 my-service
curl localhost:18081        # hello from PORT=8080
curl localhost:18090        # hello from PORT=9090

docker run -d -e PORT=8080 -p 8081:8080 us-docker.pkg.dev/cloudrun/container/hello
docker image inspect us-docker.pkg.dev/cloudrun/container/hello --format '{{.Os}}/{{.Architecture}}'
# linux/amd64
curl localhost:8081         # "It's running!"

Google 的示例是仅含 amd64 的镜像;Oxcart 拉取后直接通过 Rosetta 运行,无需额外参数。对于自己构建的仅含 amd64 的镜像,执行 docker run 时也请传入 --platform linux/amd64:在我们的测试中,只有指定平台后才能找到本地构建的 amd64 镜像。

在 Apple 芯片 上构建 linux/amd64 镜像

# Cloud Run target: amd64
docker buildx build --platform linux/amd64 --load -t my-service:amd64 .

# Both architectures in the local image store (runs locally either way)
docker buildx build --platform linux/amd64,linux/arm64 -t my-service:multi .

Oxcart 的默认构建器同时列出 linux/amd64 和 linux/arm64,多平台构建可以在本地完成,两个变体都能运行。Oxcart 不支持推送多平台镜像,因此部署到 Cloud Run 时,请推送 amd64 标签,因为它运行的就是这个变体。构建很快:小型本地构建上下文无缓存时为 341 ms,有缓存时为 121 ms,是我们测试的三个运行时中最快的。

推送到 Artifact Registry 并部署

gcloud auth configure-docker us-central1-docker.pkg.dev
docker tag my-service:amd64 us-central1-docker.pkg.dev/my-project/apps/my-service:1.0.0
docker push us-central1-docker.pkg.dev/my-project/apps/my-service:1.0.0
gcloud run deploy my-service \
  --image us-central1-docker.pkg.dev/my-project/apps/my-service:1.0.0 --region us-central1

使用 Compose 运行依赖服务

Cloud Run 服务通常需要访问数据库、缓存或其他服务。使用 Compose 将它们一同运行,在服务环境中设置 PORT,并通过健康检查控制启动顺序:

services:
  api:
    build: .
    platform: linux/amd64
    environment:
      PORT: "8080"
      REDIS_URL: redis://cache:6379
    ports: ["8080:8080"]
    depends_on:
      cache:
        condition: service_healthy
  cache:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 2s
      retries: 30

缓存通过健康检查且 API 启动后,docker compose up -d --wait 才会返回。Apple 芯片 上的 Compose 指南详细介绍了健康检查、amd64 镜像和端口。

Mac 上的端口

与 Docker 默认行为一样,发布的端口监听 Mac 的所有网络接口。如果另一个 Mac 应用已在 127.0.0.1:8080 上监听,访问 localhost:8080 可能到达该应用,而不是容器。因此,请选择空闲的宿主机端口(-p 18080:8080),同时让 PORT 保持 Cloud Run 设置的值。Oxcart 的 Ports 视图会在容器旁显示 Mac 上所有监听服务,并解释容器端口为何不响应,例如容器内的服务器绑定了 127.0.0.1;这也是 Cloud Run 会拒绝的错误。参阅Mac 上的容器网络。

常见问题

如何在 Mac 上本地运行 Cloud Run 服务?

设置 PORT 变量并发布端口后运行容器:docker run -e PORT=8080 -p 8080:8080 IMAGE。这是 Google 文档提供的 Docker 本地测试方法。在 Oxcart 上,我们使用自己的镜像在 8080 和 9090 端口验证过,也使用 Google 的 us-docker.pkg.dev/cloudrun/container/hello 示例验证过。

为什么在 Apple 芯片 上构建的镜像部署到 Cloud Run 会失败?

Google 文档说明,Cloud Run 支持 Linux x86_64 ABI,多架构镜像必须包含 linux/amd64。在 Apple 芯片 Mac 上直接执行 docker build 会生成 arm64 镜像。请使用 --platform linux/amd64 构建。

部署前能在 Mac 上运行 amd64 镜像吗?

可以。Oxcart 通过 Rosetta 运行 linux/amd64 镜像。运行本地自行构建的仅含 amd64 的镜像时,请传入 --platform linux/amd64;在我们的测试中,拉取的 amd64 镜像(如 Google 的 hello 示例)不带此参数也能运行。

容器本地能运行,但 Cloud Run 提示未能监听端口,为什么?

最常见的原因是绑定了 127.0.0.1 或硬编码端口。Cloud Run 的容器运行约定要求容器在 0.0.0.0 上监听 PORT 指定的端口。请在本地用非默认 PORT(如 9090)测试,以发现硬编码端口。

需要 gcloud beta code dev 或 Cloud Code 吗?

不需要,它们是可选项。Google 列出的本地测试方式包括普通 Docker、可访问 Google Cloud 的 Docker、Cloud Code 模拟器和 gcloud beta code dev。在 Oxcart 上使用 Docker,可以直接测试镜像及其 PORT 处理方式。gcloud beta code dev 则通过 minikube 或现有 Kubernetes 上下文提供基于 Kubernetes 的开发流程;需要这种集成时再选择它。

如何让本地容器访问 Google Cloud API?

按照 Google 文档中“可访问 Google Cloud 的 Docker”的方式挂载凭据,通常通过挂载文件和 GOOGLE_APPLICATION_CREDENTIALS 传入应用默认凭据(Application Default Credentials)。Oxcart 容器的出站连接由 Mac 建立,因此会使用你的 VPN 和 DNS。

来源与方法

  • 示例测试环境:Oxcart 0.1.2,Mac17,14,macOS 27.2,2026-10-10(PORT 设为 8080 和 9090、Google hello 示例以 linux/amd64 运行、Buildx 单平台与多平台构建)。
  • Cloud Run 容器运行约定(端口、0.0.0.0、x86_64):https://docs.cloud.google.com/run/docs/container-contract。本地测试选项:https://docs.cloud.google.com/run/docs/testing/local 和 https://docs.cloud.google.com/sdk/gcloud/reference/beta/code/dev。核查日期:2026-10-10。
  • 构建速度:Oxcart 0.1.2,2026-10-10,Apple M5 Max,8 个 CPU 和 12 GiB,取五次采样的中位数;其他运行时于同一天较早时段,在同一台 Mac 上使用相同测量工具及 docker 29.4 客户端测量。

在你自己的项目中试用 Oxcart

免费试用 60 天。之后购买一个许可证,终身包含所有更新,无需订阅。

配备 Apple silicon 的 Mac · Windows 11 (x64)

继续阅读

版本更新说明

Oxcart 26.11.6

最新版本

Containers see the changes you make to files on your Mac as they happen.

  • Edit a file in a shared folder on your Mac, and tools that watch it in a container, such as Vite, webpack and nodemon, reload right away. Polling is not needed.
  • When no containers are running and you haven't used Docker for two minutes, Oxcart gives the memory it was using back to macOS. The next docker command starts it again in under a second. This doesn't happen while Kubernetes is turned on.
  • You can bring your images, volumes and networks over from another Docker app. Choose Import from Another Runtime… in the More (…) menu on the Containers page, or run oxcart import. Containers themselves aren't copied: start them again with docker compose up -d or docker run, and they use the imported volumes and networks.
  • Bug fixes and optimizations.
  • Updated Linux and system components, with the latest security fixes. A Windows virtual machine that is suspended when you update starts fresh afterwards.

需要 macOS 26.0 或更高版本

Oxcart 26.11.5

You can now turn on GPU acceleration for a Windows 11 virtual machine you already have.

  • Open the virtual machine's settings and turn on GPU acceleration under Display. Oxcart restarts Windows once, and the Windows desktop and Direct3D 10 and 11 apps then render on your Mac's GPU.
  • Turning GPU acceleration off puts back the standard display driver, and suspending works again.

需要 macOS 26.0 或更高版本

Oxcart 26.11.4

Bug fixes and optimizations.

  • Virtual machines start again after updating Oxcart while it is open.

需要 macOS 26.0 或更高版本

Oxcart 26.11.3

Windows virtual machines can now use your Mac's GPU.

  • Turn on GPU acceleration when you create a Windows 11 virtual machine, on the first step of New Virtual Machine. The Windows desktop and Direct3D 10 and 11 apps then render on your Mac's GPU instead of its processor.
  • A virtual machine with GPU acceleration can't be suspended or snapshotted while it runs. Shut it down instead. Existing virtual machines are not changed.
  • GPU acceleration is new. After a lot of opening and closing windows, the Windows screen can go black for about a second while Oxcart frees graphics memory.
  • Updated Linux and system components, with the latest security fixes.

需要 macOS 26.0 或更高版本

Oxcart 26.11.2

Oxcart can now run Kubernetes for you.

  • Turn on Kubernetes in Settings › Resources to get a local single-node cluster that kubectl can use right away.
  • Services in the cluster are reachable from your Mac at 127.0.0.1, and images you build with Docker run in the cluster without pushing them to a registry.
  • Updated Linux and system components, with the latest security fixes.

需要 macOS 26.0 或更高版本

Oxcart 26.11.1

Bug fixes and optimizations.

  • A simpler toolbar in the VM window.
  • Updated Linux and system components, with the latest security fixes.

需要 macOS 26.0 或更高版本

Oxcart 26.11.0

Clearer Windows audio, a network that comes back, and a VM toolbar that stays out of your way.

  • Clear Windows audio. Choppy, garbled sound in Windows VMs is fixed.
  • Networking that recovers. Turn a Windows VM's network off and on again, and it reconnects without a restart.
  • A toolbar that stays out of the way. It no longer covers the top of your VM. Move the pointer to the top center and click the small tab when you want it.
  • Simpler Oxcart Tools for Windows. One CD now holds everything, and the installer handles the drivers and any restart for you.
  • A more dependable clipboard in Windows VMs.
  • A license agreement to accept the first time you open Oxcart on your Mac.
  • Updated Linux, container and Docker components, with the latest security fixes.

需要 macOS 26.0 或更高版本

Oxcart 26.10.0

Virtual machines are here. Windows 11, Linux and macOS run on your Mac, built into Oxcart beside your containers and covered by the license you already have.

  • Windows 11 in about 5 minutes, hands off. Choose your Windows 11 ARM installer and walk away: Oxcart installs Windows, its drivers and Oxcart Tools by itself, on a VM with real TPM 2.0 and Secure Boot. You bring the installer and the license.
  • Linux in under a minute. Ubuntu, Debian and Fedora start with your Mac username, your SSH key and passwordless sudo already set up; Fedora is ready in about 30 seconds. Every further VM from the same image starts from an instant copy that takes only the space it changes. Ubuntu Desktop, Fedora Workstation and any arm64 Linux installer work too.
  • macOS on macOS. Oxcart restores the newest macOS your Mac supports and, with Automatic setup, creates your account and installs Oxcart Tools.
  • Every VM is a real Mac app. Each one has its own window, Dock icon and ⌘-Tab entry, and keeps running after you quit Oxcart. The Retina display follows the window as you resize it or go full screen, ⌘C and ⌘V work in Linux and Windows, and text, images and files move between your Mac and the guest by copy, paste and drag.
  • Snapshots that capture the moment. Snapshot a running VM with its open apps and return to that exact moment later. Snapshots and clones take almost no space until the guest changes, and a restore lands whole even if your Mac loses power halfway.
  • Your Mac's folders, network and USB. Share Mac folders with any guest, reach your Mac by name and publish ports from the VM. Hand a USB device to Windows for flashers, programmers and dongles; development boards' serial ports show up in Windows under their own IDs.
  • First-class for coding agents. VMs join containers in Oxcart's MCP server with 22 tools of their own, so an agent you connect can create, start, snapshot and clone VMs, run commands and copy files in the guest, forward ports, connect USB devices and disk images, and read the screen and type in any guest, even one without Oxcart Tools, all within the permission level you set for each agent. The oxcart vm command covers every operation, with JSON output for scripts and CI.
  • Encrypted VMs, when you want them. Keep a VM's disks and secrets behind a password of your own, with AES-256 encryption built into Oxcart, so an encrypted disk flushes as fast as a plain one.
  • Disk space you can see. Choose where a VM lives, on your Mac or an external drive, and see what it takes now and what it can grow to against the space you have. Reclaim Space hands back what a guest frees right away, and Disk Usage shows each downloaded system so you can remove the ones you no longer need.
  • VMs that move with you. Each VM is a single item in Finder you can keep on any drive. Export it as one .oxvm file to another Mac, and bring over Linux and macOS VMs from another Mac virtualization app.
  • Ready when you are. Chosen VMs start when you log in, run headless with no window at all, and suspend when you close them, so you pick up exactly where you left off.
  • Oxcart Help. Help › Oxcart Help (⌘?) explains every setting, what it does and what changing it affects, with a ? beside each one. Coding agents read the same help through MCP.
  • More reliable published ports. A container connection that a service closes mid-transfer now ends cleanly instead of waiting.
  • New version numbers. Releases are now numbered by year and month, so this one is 26.10.0.

需要 macOS 26.0 或更高版本

Oxcart 0.1.8

Oxcart 现已支持 Windows,购买后可终身享有所有更新。

  • Oxcart 也能在 Windows 上运行。一份许可证最多可用于 5 台设备,Mac 与 Windows 可任意组合。
  • 终身包含每次更新。
  • 截至 2026 年 12 月 31 日,Oxcart 售价为 $5。
  • 编程智能体可以检查容器、读取实时统计数据和资源压力、跟踪日志、追踪耗时较长的镜像拉取和构建,并按你设置的限制运行容器。
  • 重新创建容器时会保留其卷和网络别名。
  • Oxcart 的辅助程序在“登录项”中显示为 Oxcart。
  • 全面提升可靠性。

需要 macOS 26.0 或更高版本

Oxcart 0.1.7

更快的共享文件夹、更快的网络,以及可编辑的容器环境。

  • 共享文件夹大幅提速。在共享文件夹中克隆仓库、安装软件包和构建,速度最高可达原来的 3×。
  • 网络更快。发布端口和容器连接可传输近两倍的数据,同时减少 CPU 占用。
  • 按需启用加密。Mac 与容器之间的流量加密是可选的:可在 Settings › Resources › Encrypt container connections 中开启。
  • 环境变量更易查看和修改。在容器的 Overview 中查看变量,通过 Edit and Recreate 修改变量,还能一次粘贴整个 .env 文件。
  • Run Container 面板操作更顺畅。按 Return 会移至下一行,不会启动容器。
  • 故障排查更清晰。当 VPN 或防火墙拖慢连接时,Oxcart 会告知你。
  • 共享文件夹更可靠,能正确报告权限错误,并在 Mac 上的文件发生变更后及时更新内容。

需要 macOS 26.0 或更高版本

Oxcart 0.1.6

编程智能体可以修复所发现的问题,另有全面的问题修复与安全加固。

  • 新添加的智能体可以使用 Mac 上已有的镜像来启动、停止和重启容器,在容器内运行命令,以及启动 Compose 项目。拉取、构建和删除需要 Full 权限,可在 MCP Integrations 中为每个智能体分别设置。
  • 设置时会为每个智能体提供可直接使用的配置条目,运行 oxcart mcp check 可确认其是否正常工作。
  • 回答更准确:智能体能识别服务是否因其依赖的服务停机而停机、网页是否确实能加载,以及故障的原因和修复方法。
  • Start at login 会在登录时将 Oxcart 启动到菜单栏,随时可用。
  • Oxcart 启动时会检查更新,并向 oxcart.cc 发送一条简短的联络请求。Settings › Privacy 中会完整显示其中包含的内容。
  • 容器从启动之初就能发现所在网络中的其他服务。
  • 修复了特权容器、Rosetta 检查和设置过程中的安全防护问题。
  • Oxcart 应用会在执行任何删除数据或停止正在运行的任务的操作前征求确认。
  • 全面加强安全防护并提升可靠性。

需要 macOS 26.0 或更高版本

Oxcart 0.1.5

Oxcart 支持运行本地 Kubernetes 和特权容器,并提供十种语言。

  • 在 Settings › Resources › Kubernetes and networking 中开启特权容器,即可运行 kind、k3d、minikube(Docker 驱动)和 Docker-in-Docker,并使用 docker run --privileged 和 --device。此功能默认关闭。Oxcart 的防护机制会阻止每个容器访问 Oxcart 的磁盘、内核、其他容器的数据,以及 Oxcart 与 Mac 之间的通信通道。
  • 支持 IPv6 容器网络,此功能也默认关闭,适用于使用 IPv6 创建的网络,例如 kind 的双栈网络。
  • Oxcart 已翻译为简体中文、日语、德语、法语、西班牙语、巴西葡萄牙语、韩语、俄语和土耳其语。Settings › General › Language 中的语言设置仅对 Oxcart 生效。

需要 macOS 26.0 或更高版本

Oxcart 0.1.4

许可证功能与细节改进。

  • 通过安全邮件链接激活许可证。
  • 在 Settings 中管理许可证和 Mac。
  • 离线验证许可证。
  • 性能提升、界面优化与问题修复。

需要 macOS 26.0 或更高版本

Oxcart 0.1.3

空闲时回收内存。

  • 没有容器运行时回收 VM 内存。
  • 保留容器、镜像、卷和网络。

需要 macOS 26.0 或更高版本

Oxcart 0.1.2

命令行工具集成。

  • 在 Oxcart 自带的 Docker 工具与已安装的 Docker 工具之间切换。
  • 界面优化。

需要 macOS 26.0 或更高版本

Oxcart 0.1.1

内置 Docker 工具与智能体控制。

  • 自带 Docker CLI 29.9、Compose 5.6 和 Buildx 0.38。
  • Docker 上下文集成与安全的钥匙串凭据存储。
  • MCP 智能体连接,支持为各智能体设置权限或阻止访问。

需要 macOS 26.0 或更高版本

Oxcart 0.1.0

适用于 Apple 芯片的 Docker 兼容容器。

  • 兼容 Docker CLI、Compose 和 Buildx。
  • 自带运行时组件,可离线设置。
  • 按项目和 Git 分支整理端口。
  • MCP 集成,默认仅允许只读访问。
  • 经过验证的自动更新。

需要 macOS 26.0 或更高版本