-
探索容器机
了解容器机,这是开源项目 Container 中新增的一款工具,可为 Mac 提供持久的轻量级 Linux 环境。探索容器机的工作原理,以及容器化设计如何在 macOS 上的 Linux 开发流程中提供顺畅丝滑的高性能体验。
章节
- 0:00 - Introduction
- 1:19 - Containerization
- 2:14 - Design principles
- 3:36 - Container machine
- 4:36 - Demo
- 10:33 - Next steps
资源
相关视频
WWDC25
-
搜索此视频…
大家好 我是Michael 今天我想介绍一项基于 Containerization构建的新功能
Containerization是在macOS上 运行Linux容器的Swift框架 专注于安全性 隐私保护和性能
Linux容器是构建 测试 和部署服务端应用的绝佳方式
在此基础上 Container machine 是一项提供高度集成 Linux环境的新功能 可在你的Mac上无缝运行 Container machine如容器般 快速且轻量 同时像虚拟机一样持久化 结合宿主机集成 Container machine宛如macOS原生 在深入了解 Container machine之前 让我们先回顾一下 Containerization框架 我们将了解塑造了 Container machine的设计原则
最后 我们将探索 Container machine 如何为跨平台开发 提供无缝工作流
在WWDC 25上 我们将 Containerization开源了
Containerization是在macOS上 运行Linux容器的Swift框架 提供了存储 网络 执行 和Linux init系统的API
其设计为每个容器提供 基于虚拟机的隔离 这些轻量级虚拟机性能出色 启动时间不足一秒
与Containerization一同 container工具也已开源 提供用于镜像创建 和分发的CLI命令 以及Linux容器的 生命周期管理 如需了解Containerization 整体架构的更多信息 以及container工具 请观看 WWDC 25的《Meet Containerization》 现在 让我们看看 Container machine的设计原则 这些环境应当 快速且轻量 以融入现有工作流 在macOS和Linux之间 切换应轻而易举
用户应能快速自定义 并创建新环境 快速创建使多个项目 能各有专属环境 无需担心依赖冲突 或工具链问题
开发生命周期中通常需要 不同的工具和依赖 有了持久化环境 可以随时添加并使用 更多工具 最后 这些Linux环境应 融入你现有的工作流 多平台开发不应 带来大量上下文切换 不应需要学习新工具 才能面向不同环境开发
构建Container machine时 我们牢记这些设计原则 Container machine必须 快速且轻量 必须易于管理 必须提供持久化 让用户随时继续工作 Container machine必须 如同macOS的延伸 带着这些设计原则 让我们看看Container machine 如何改善跨平台工作流 基于Containerization构建 每个Container machine运行于 各自的轻量级虚拟机中 并使用与容器相同 的镜像格式
它是container工具的一等功能 并具有熟悉的用户体验 用container工具构建的镜像 可作为新Container machine 的起始点
Container machine是有状态的 持久保存工作期间的修改 即你在其中的操作 按需启动和停止项目 Container machine确保环境 能从上次停止处继续
通过自动用户映射 共享文件系统支持 以及随时进入 Linux环境的能力 无论你在终端的哪个位置 Container machine 提供流畅的过渡 从macOS切换到Linux 再切换回来 现在 让我们看看 Container machine实际效果 让我们从container machine开始
这里展示了可执行 操作的概览 包括create run和stop等 要创建新的Container machine 我将使用container machine create
我会为它命名 并将其 设为Mac上的默认machine 这样每次命令就不用 再提供名称了
Container machine使用与容器 相同的OCI镜像 一种常用的容器镜像是alpine
很好 Container machine 已创建完成
接下来 我想在这个 Container machine内执行命令 我将使用container machine run 来执行echo命令
很好 让我们用uname试试
在macOS上uname 输出Darwin
container machine run uname 输出Linux 反映了运行时环境
Container machine会自动 映射你的用户名 以及Mac上的 当前工作目录 在Mac上运行whoami 返回Michael
运行pwd显示我位于 macOS用户主目录
让我们在Container machine内 运行交互式shell container machine run 不加额外参数 将启动交互式会话
在container machine内部 运行whoami和pwd 返回与Mac上相同的 用户名和路径
很好!
自动用户创建 文件系统共享 以及一致的工作目录 带来了无缝体验 让我们深入探索 看看我正在构建的应用 我有一个基于Vapor的Web服务器 想在Linux上运行和部署 在我的工作流中 我在Mac上用Xcode编辑项目 我用macOS工具 为应用编辑图片 我将在Linux上构建并运行它 然后通过Safari从macOS 访问Web服务器来测试修改 让我们来处理这个应用 在终端中运行ls 显示我的项目文件
我有Package.swift 源代码 以及存放资源的Public目录 我有一个安装了 Swift工具链的Container machine container machine list 将显示名称 IP地址以及所有 Container machine的资源信息
我将复制IP地址备用
我已准备好在Linux上 测试我的应用 我将先启动交互式shell 在Container machine内 通过运行container machine run
通过自动目录共享 所有项目文件均可访问
我的Container machine 有一个隔离的网络 Mac上的Safari 若要访问Web服务器 运行在Container machine内的 我需要确保Vapor 监听外部接口 让我们在Xcode中更新 服务器配置
我会将配置的hostname 设为Container machine的IP地址 我们之前已复制了这个值 我在Mac上的Xcode中 编辑了这个文件 但这些更改已 在Container machine中生效 回到终端 我准备好编译 并运行应用了
很好 服务器正在运行 让我们在Safari中查看网站 我将打开Safari并粘贴 Container machine的IP地址 到地址栏中 我还会添加端口8080
很好 访问成功 我能看这个画面一整天!
不过 让我们再做最后一个修改 我使用Icon Composer 创建了屏幕上的存储图标 我想将图标的 背景改为渐变色 我将在Icon Composer中打开 现有图标文件来进行修改
现在 我将把这个图标导出到 项目并覆盖现有文件
无需将文件复制到 Container machine中 我预计刷新Safari中的页面 会自动显示更新后的图标 让我们回到Safari
很好!更新已生效
Container machine汇聚了 容器的易用性和速度 以及虚拟机的持久化 无缝集成提供了 一个Linux环境 如同你Mac的延伸 我们期待你 试用Container machine 在Github上下载 container工具的最新版本 期待你的反馈 感谢收看!
-
-
4:41 - Viewing container machine commands
container machine -
5:00 - Creating a new container machine
container machine create --name demo --set-default alpine -
5:39 - Echo hi
container machine run echo hi -
5:57 - Running uname
container machine run uname -
6:28 - Start interactive shell
container machine run -
8:01 - List container machines
container machine list -
8:22 - Start interactive shell
container machine run -
9:13 - Run the application
swift run
-
-
- 0:00 - Introduction
Introduces Container machine, a new feature built on the Containerization framework that provides a fast, lightweight, and persistent Linux environment seamlessly integrated with macOS.
- 1:19 - Containerization
Reviews the open-source Containerization Swift framework — its architecture, VM-based isolation, sub-second start times, and the companion container CLI tool.
- 2:14 - Design principles
Outlines the four principles that shaped Container machine: fast and lightweight, simple to create and operate, persistent across sessions, and a seamless extension of macOS.
- 3:36 - Container machine
Explores how Container machine builds on Containerization with OCI image support, first-class integration into the container tool, stateful persistence, and automatic user and filesystem mirroring.
- 4:36 - Demo
Demonstrates creating and running a Container machine, executing commands with automatic user and directory mirroring, and building and testing a Vapor web server from macOS using Xcode, Icon Composer, and Safari.
- 10:33 - Next steps
Recaps Container machine key strengths and encourages viewers to download the latest container 1.0 release from GitHub to try it in their workflow.