apple-container-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseApple Container Skill
Apple Container 技能
To use the Apple Container CLI, execute the commands below using the tool.
Note: This CLI is specific to Apple's container implementation.
run_shell_command要使用Apple Container CLI,请使用工具执行以下命令。
**注意:**此CLI是Apple专属的容器实现工具。
run_shell_commandCommon Workflows & Architecture
常见工作流与架构
These patterns represent best practices for using the Apple Container CLI effectively.
这些模式代表了有效使用Apple Container CLI的最佳实践。
1. System Lifecycle Management
1. 系统生命周期管理
Unlike standard Docker Desktop, the container system services are explicit.
- Startup: Always verify before running operations. If stopped, run
container system status.container system start - Kernel: On first run, may prompt to install a Linux kernel. The agent should be aware of this initialization step.
system start - Cleanup: To save resources when not in use, run .
container system stop
与标准Docker Desktop不同,容器系统服务是显式管理的。
- **启动:**在运行操作前,请务必先验证。如果服务已停止,请运行
container system status。container system start - **内核:**首次运行时,可能会提示安装Linux内核。Agent需要注意这个初始化步骤。
system start - **清理:**当不使用容器时,为节省资源,请运行。
container system stop
2. Networking & Connectivity
2. 网络与连接
- DNS: For stable service discovery, configure a local domain:
- (e.g.,
sudo container system dns create <domain>)test container system property set dns.domain <domain>- Access containers via .
http://<container-name>.<domain>
- Inter-Container: Containers are on a . Direct IP communication (
vmnet) works but can be fragile due to isolation.192.168.64.x - Host Gateway Strategy (Reliable Fallback): If network plugins are missing or you encounter "No route to host":
- Publish the service port to the host (e.g., ).
-p 5432:5432 - Connect from other containers using the Host Gateway IP ().
192.168.64.1 - Note: Disable SSL () if connection resets occur via the gateway.
sslmode=disable
- Publish the service port to the host (e.g.,
- Localhost: Port forwarding () works as expected for accessing containers from the host.
-p 8080:80
- **DNS:**为实现稳定的服务发现,请配置本地域名:
- (例如:
sudo container system dns create <domain>)test container system property set dns.domain <domain>- 通过访问容器。
http://<container-name>.<domain>
- **容器间通信:**容器位于网络中。直接IP通信(
vmnet)可行,但由于隔离机制可能不稳定。192.168.64.x - **主机网关策略(可靠备选方案):**如果缺少网络插件或遇到“无法访问主机”错误:
- 将服务端口发布到主机(例如:)。
-p 5432:5432 - 使用主机网关IP()从其他容器连接。
192.168.64.1 - *注意:*如果通过网关连接时出现重置问题,请禁用SSL()。
sslmode=disable
- 将服务端口发布到主机(例如:
- **本地主机:**端口转发()可按预期工作,用于从主机访问容器。
-p 8080:80
3. Data Persistence
3. 数据持久化
- Volume Initialization: New volumes may contain a directory, which can cause "directory not empty" errors.
lost+found - Best Practice: Always configure services (like PostgreSQL) to use a subdirectory within the volume.
- Example: instead of the root mount point.
PGDATA=/var/lib/postgresql/data/pgdata
- Example:
- **卷初始化:**新卷可能包含目录,这会导致“目录非空”错误。
lost+found - 最佳实践:始终配置服务(如PostgreSQL)使用卷内的子目录。
- *示例:*使用而非根挂载点。
PGDATA=/var/lib/postgresql/data/pgdata
- *示例:*使用
4. Development Patterns
4. 开发模式
- Git/SSH: Use the flag (
--ssh) to forward the host's SSH agent. This is the preferred method for cloning private repositories inside containers.container run --ssh ... - Hot Reloading: Use (e.g.,
--volume) to mount source code for immediate feedback, just like standard Docker.-v $(pwd):/app - Builder Tuning: The build process runs in its own VM. For large builds, explicitly scale the builder: .
container builder start --cpus 4 --memory 8g
- **Git/SSH:**使用标志(
--ssh)转发主机的SSH代理。这是在容器内克隆私有仓库的首选方法。container run --ssh ... - **热重载:**使用(例如:
--volume)挂载源代码以获得即时反馈,与标准Docker的用法一致。-v $(pwd):/app - **构建器调优:**构建过程在独立VM中运行。对于大型构建,请显式扩展构建器:。
container builder start --cpus 4 --memory 8g
Critical Setup
关键设置
Before running containers, the system services usually need to be running.
- Check Status:
container system status - Start Services: (may require
container system startif installing kernel/root components, but usually run as user)sudo
在运行容器前,系统服务通常需要处于运行状态。
- 检查状态:
container system status - 启动服务:(如果安装内核/根组件可能需要
container system start,但通常以普通用户身份运行即可)sudo
Commands
命令
System Management
系统管理
- : Starts the container services.
container system start- Options: ,
--enable-kernel-install,--disable-kernel-install,--app-root <path>.--install-root <path>
- Options:
- : Stops the container services.
container system stop- Options: .
--prefix <string>
- Options:
- : Checks if services are running.
container system status - : Shows CLI and API server versions.
container system version - : Displays system logs.
container system logs- Options: ,
--follow(e.g.,--last <time>,5m).1h
- Options:
- : Shows disk usage.
container system df - : Creates a local DNS domain (requires sudo).
container system dns create <domain> - : Lists configured local DNS domains.
container system dns list - : Deletes a local DNS domain (requires sudo).
container system dns delete <domain> - : Lists system properties (config).
container system property list - : Gets a system property value.
container system property get <id> - : Sets a system property.
container system property set <id> <value>- Examples:
container system property set dns.domain my.local
- Examples:
- : Resets a system property to default.
container system property clear <id> - : Installs/updates the Linux kernel.
container system kernel set- Options: ,
--recommended,--arch <arch>.--binary <path>
- Options:
- :启动容器服务。
container system start- 选项:,
--enable-kernel-install,--disable-kernel-install,--app-root <path>。--install-root <path>
- 选项:
- :停止容器服务。
container system stop- 选项:。
--prefix <string>
- 选项:
- :检查服务是否运行。
container system status - :显示CLI和API服务器版本。
container system version - :显示系统日志。
container system logs- 选项:,
--follow(例如:--last <time>,5m)。1h
- 选项:
- :显示磁盘使用情况。
container system df - :创建本地DNS域名(需要sudo权限)。
container system dns create <domain> - :列出已配置的本地DNS域名。
container system dns list - :删除本地DNS域名(需要sudo权限)。
container system dns delete <domain> - :列出系统属性(配置)。
container system property list - :获取系统属性值。
container system property get <id> - :设置系统属性。
container system property set <id> <value>- 示例:
container system property set dns.domain my.local
- 示例:
- :将系统属性重置为默认值。
container system property clear <id> - :安装/更新Linux内核。
container system kernel set- 选项:,
--recommended,--arch <arch>。--binary <path>
- 选项:
Container Lifecycle
容器生命周期
- : Runs a command in a new container.
container run [OPTIONS] IMAGE [COMMAND] [ARG...]- Common Options:
- : Run in background.
-d, --detach - : Keep STDIN open.
-i, --interactive - : Allocate a pseudo-TTY.
-t, --tty - : Publish a port.
-p, --publish <host-port:container-port> - : Mount a volume.
-v, --volume <host-path:container-path> - : Assign a name.
--name <string> - : Remove after stop.
--rm - : Set environment variable.
-e, --env <key=value> - : Set user (name|uid[:gid]).
-u, --user <user> - : Set working directory.
-w, --workdir <dir> - : CPU limit.
-c, --cpus <count> - : Memory limit (e.g.,
-m, --memory <size>,512M).2G
- Common Options:
- : Creates a container without starting it (same options as
container create [OPTIONS] IMAGE [ARG...]).run - : Starts stopped containers.
container start [OPTIONS] CONTAINER...- Options: ,
-a, --attach.-i, --interactive
- Options:
- : Stops running containers.
container stop [OPTIONS] CONTAINER...- Options: (wait before kill),
-t, --time <seconds>.-s, --signal <signal>
- Options:
- : Kills containers immediately.
container kill [OPTIONS] CONTAINER...- Options: .
-s, --signal <signal>
- Options:
- : Deletes containers (aliases:
container delete [OPTIONS] CONTAINER...).rm- Options: (delete even if running).
-f, --force
- Options:
- : Executes a command in a running container.
container exec [OPTIONS] CONTAINER COMMAND [ARG...]- Options: ,
-it,-d,-w,-e.-u, --user
- Options:
- : Lists containers (aliases:
container list [OPTIONS],ls).ps- Options: (show stopped too),
-a, --all(quiet, IDs only).-q
- Options:
- : JSON details of containers.
container inspect CONTAINER... - : Fetches container logs.
container logs [OPTIONS] CONTAINER- Options: ,
-f, --follow,--tail <n>(show boot logs).--boot
- Options:
- : Live stream of resource usage.
container stats- Options: .
--no-stream
- Options:
- :在新容器中运行命令。
container run [OPTIONS] IMAGE [COMMAND] [ARG...]- 常见选项:
- :在后台运行。
-d, --detach - :保持STDIN打开。
-i, --interactive - :分配伪终端。
-t, --tty - :发布端口。
-p, --publish <host-port:container-port> - :挂载卷。
-v, --volume <host-path:container-path> - :分配名称。
--name <string> - :停止后自动删除容器。
--rm - :设置环境变量。
-e, --env <key=value> - :设置用户(名称|uid[:gid])。
-u, --user <user> - :设置工作目录。
-w, --workdir <dir> - :CPU限制。
-c, --cpus <count> - :内存限制(例如:
-m, --memory <size>,512M)。2G
- 常见选项:
- :创建容器但不启动(选项与
container create [OPTIONS] IMAGE [ARG...]相同)。run - :启动已停止的容器。
container start [OPTIONS] CONTAINER...- 选项:,
-a, --attach。-i, --interactive
- 选项:
- :停止运行中的容器。
container stop [OPTIONS] CONTAINER...- 选项:(终止前等待时间),
-t, --time <seconds>。-s, --signal <signal>
- 选项:
- :立即终止容器。
container kill [OPTIONS] CONTAINER...- 选项:。
-s, --signal <signal>
- 选项:
- :删除容器(别名:
container delete [OPTIONS] CONTAINER...)。rm- 选项:(即使容器运行中也删除)。
-f, --force
- 选项:
- :在运行中的容器内执行命令。
container exec [OPTIONS] CONTAINER COMMAND [ARG...]- 选项:,
-it,-d,-w,-e。-u, --user
- 选项:
- :列出容器(别名:
container list [OPTIONS],ls)。ps- 选项:(同时显示已停止的容器),
-a, --all(仅显示ID)。-q
- 选项:
- :查看容器的JSON详情。
container inspect CONTAINER... - :获取容器日志。
container logs [OPTIONS] CONTAINER- 选项:,
-f, --follow,--tail <n>(显示启动日志)。--boot
- 选项:
- :实时流式显示资源使用情况。
container stats- 选项:。
--no-stream
- 选项:
Image Management
镜像管理
- : Builds an image from a Dockerfile.
container build [OPTIONS] PATH- Options: ,
-t <tag>,-f <dockerfile>,--build-arg <key=val>,--no-cache.-o, --output <type>
- Options:
- : Pulls an image from a registry.
container image pull [OPTIONS] NAME[:TAG]- Options: ,
--platform <os/arch>,--arch <arch>.--os <os>
- Options:
- : Pushes an image.
container image push NAME[:TAG] - : Lists local images (aliases:
container image list,ls).images - : Deletes images (aliases:
container image delete IMAGE...,rm).rmi - : Removes unused images.
container image prune - : Tags an image.
container image tag SOURCE TARGET - : JSON details of images.
container image inspect IMAGE... - : Saves image to tar.
container image save -o <path> IMAGE- Options: .
--platform <os/arch>
- Options:
- : Loads image from tar.
container image load -i <path>
- :从Dockerfile构建镜像。
container build [OPTIONS] PATH- 选项:,
-t <tag>,-f <dockerfile>,--build-arg <key=val>,--no-cache。-o, --output <type>
- 选项:
- :从镜像仓库拉取镜像。
container image pull [OPTIONS] NAME[:TAG]- 选项:,
--platform <os/arch>,--arch <arch>。--os <os>
- 选项:
- :推送镜像到仓库。
container image push NAME[:TAG] - :列出本地镜像(别名:
container image list,ls)。images - :删除镜像(别名:
container image delete IMAGE...,rm)。rmi - :删除未使用的镜像。
container image prune - :为镜像打标签。
container image tag SOURCE TARGET - :查看镜像的JSON详情。
container image inspect IMAGE... - :将镜像保存为tar文件。
container image save -o <path> IMAGE- 选项:。
--platform <os/arch>
- 选项:
- :从tar文件加载镜像。
container image load -i <path>
Volume Management
卷管理
- : Creates a volume.
container volume create [OPTIONS] NAME- Options: ,
-s, --size <size>.--label <key=val>
- Options:
- : Lists volumes (aliases:
container volume list).ls - : JSON details.
container volume inspect NAME... - : Deletes volumes (aliases:
container volume delete NAME...).rm - : Removes unused volumes.
container volume prune
- :创建卷。
container volume create [OPTIONS] NAME- 选项:,
-s, --size <size>。--label <key=val>
- 选项:
- :列出卷(别名:
container volume list)。ls - :查看卷的JSON详情。
container volume inspect NAME... - :删除卷(别名:
container volume delete NAME...)。rm - :删除未使用的卷。
container volume prune
Network Management
网络管理
- : Creates a network.
container network create NAME- Options: ,
--subnet <cidr>,--subnet-v6 <cidr>.--label <key=val>
- Options:
- : Lists networks (aliases:
container network list).ls - : JSON details.
container network inspect NAME... - : Deletes networks (aliases:
container network delete NAME...).rm - : Removes unused networks.
container network prune
- :创建网络。
container network create NAME- 选项:,
--subnet <cidr>,--subnet-v6 <cidr>。--label <key=val>
- 选项:
- :列出网络(别名:
container network list)。ls - :查看网络的JSON详情。
container network inspect NAME... - :删除网络(别名:
container network delete NAME...)。rm - :删除未使用的网络。
container network prune
Registry & Builder
镜像仓库与构建器
- : Log in to a registry.
container registry login SERVER- Options: ,
-u <username>,--password-stdin.--scheme <auto|https|http>
- Options:
- : Log out.
container registry logout SERVER - : Check BuildKit builder status.
container builder status - : Start the builder manually.
container builder start- Options: ,
--cpus <count>.--memory <size>
- Options:
- : Stops the builder.
container builder stop - : Deletes the builder.
container builder delete - : Clear builder cache.
container builder prune
- :登录镜像仓库。
container registry login SERVER- 选项:,
-u <username>,--password-stdin。--scheme <auto|https|http>
- 选项:
- :登出镜像仓库。
container registry logout SERVER - :检查BuildKit构建器状态。
container builder status - :手动启动构建器。
container builder start- 选项:,
--cpus <count>。--memory <size>
- 选项:
- :停止构建器。
container builder stop - :删除构建器。
container builder delete - :清理构建器缓存。
container builder prune