Telepresence `compose stop` 命令详解:停止扩展服务并优雅结束附件连接
云原生开发工具微服务网络【免费下载链接】telepresenceLocal development against a remote Kubernetes or OpenShift cluster项目地址https://gitcode.com/gh_mirrors/te/telepresence点击查看免费下载telepresence compose stop是 Telepresence 的 Docker Compose 扩展命令族中的停止子命令用于停止由telepresence compose up启动的本地容器同时结束这些服务在远端 Kubernetes/OpenShift 集群上建立的 intercept、ingest、replace、wiretap 等附件attachment连接。本文以 docs/reference/cli/telepresence_compose_stop.md 为骨架结合 compose 扩展机制文档 与 compose 子命令实现源码完整讲解该命令的语法、全部参数、与原生docker compose stop的本质区别以及它在up生命周期中的自动调用场景。命令概览语法与定位telepresence compose stop的用法与原生 Docker Compose 保持高度一致telepresence compose stop [flags] [services]从 compose.go 命令注册入口 可以看到所有telepresence compose子命令都通过compose.GenerateSubCommands(cmd)动态生成其定义数据来自内嵌的 dc-cli.json对应其中name: stop、usage: docker compose stop [OPTIONS] [SERVICE...]的命令描述因此参数风格与docker compose保持一致。未指定[services]时停止项目内所有服务指定一个或多个服务名时仅停止列出的服务。该命令的定位可以从 docs/reference/compose.md 的 States 一节得到权威解释telepresence compose stopends the attachments, but it keeps telepresence connected, because the existing containers use theteleroutenetwork backed by that connection.即stop 会结束附件远端集群侧的资源占用但不会退出 Telepresence 连接——因为容器仍在运行期间依赖teleroute网络访问集群连接需要保留。只有telepresence compose down才会彻底终止网络并退出 Telepresence。参数详解四组 Flag 的完整说明该命令共包含四组参数命令自身 Flag、Compose 通用 Flag、Compose stop 专属 Flag 与全局 Flag。命令 FlagFlag说明-h, --help显示 stop 命令的帮助信息Compose 通用 Flag所有 compose 子命令共享这些 Flag 由 config.go 中的 addComposeFlags 函数 统一注册对stop同样生效Flag类型说明--env-file stringArray可重复指定可选的 environment 文件env 文件按出现顺序依次加载可多次传入-f, --file stringArray可重复指定 Compose 配置文件可传入多个如-f docker-compose.yml -f docker-compose.override.yml--profile stringArray可重复启用指定 profile多次传入可启用多个 profile--project-directory string字符串指定备用的工作目录默认为第一个指定的 Compose 文件所在目录--project-name string字符串指定项目名称从 toProjectOptions 实现 可以看到这些参数在底层如何被解析项目工作目录来自projectDirenv 文件按--env-file显式指定、当前目录.env、COMPOSE_FILE环境变量、默认compose.yaml探测的优先级顺序加载profiles 与 project name 分别注入WithDefaultProfiles与WithName。在生成最终转发的docker compose命令行时createProject 会把--project-name、--project-directory、--env-file、--profile等原样透传给底层 docker CLI。Compose stop 专属 FlagFlag类型说明-t, --timeout int整数指定停止shutdown超时时间单位为秒。对应 dc-cli.json 中 stop 的 timeout 定义在停止容器时限制等待其优雅退出的时长值得注意dc-cli.json 中stop还声明了一个--dry-run布尔 Flag但它在 subCommand 生成阶段 被隐藏并且当用户显式传入--dry-run时run 函数会直接报错因为 Telepresence 必须实际挂接到工作负载才能获取修改 compose 项目所需的数据intercept、replace、ingest、wiretap 都会安装 traffic-agent无法作为 dry-run 执行。全局 FlagFlag说明--config stringTelepresence 配置文件路径--format string输出格式支持json、yaml、json-stream、default默认default--progress string进度输出类型auto、tty、plain、json、quiet默认auto--use string匹配表达式用于唯一标识 daemon 容器其中--progress的值会被 run 函数 读取并传给底层 compose非auto时以显式--progress mode透传见 createProject。与原生docker compose stop的区别附件生命周期这是使用本命令时必须理解的核心差异。普通docker compose stop只停止容器进程而telepresence compose stop是Telepresence 扩展的 compose 生命周期管理的一部分。完整状态语义如下命令容器附件intercept/ingest/replace/wiretap 等Telepresence 连接compose up启动/确保运行建立建立compose create创建但不启动建立后结束保留compose stop停止结束保留compose down删除结束退出telepresence quit——若检测到 compose 正在运行先执行compose down从 run 函数 的源码可以看到当命令名是create、stop或非 detached 模式的up时在底层docker compose命令执行完毕后会调用tr.detach(ctx)结束所有附件——stop正是触发 detach 的命令之一。detach 过程transform.go 中的 detach 方法会遍历全部 attachment逐个执行其deactivate()释放远端资源。典型使用场景与示例场景一手动停止整个项目# 停止项目内所有服务结束附件保留连接 telepresence compose stop # 指定项目目录与项目名 telepresence compose --project-name myapp --project-directory ./stack stop # 从多个配置文件和 profile 构建项目后停止 telepresence compose -f docker-compose.yml -f docker-compose.prod.yml --profile prod stop场景二仅停止指定服务# 只停止 db 服务其他服务不受影响 telepresence compose stop db # 停止多个服务并指定 30 秒优雅退出超时 telepresence compose stop -t 30 db web由于子命令在第一个非 Flag 参数即服务名处停止解析 Flag见 subCommand 中SetInterspersed(false)的设置telepresence compose stop db web中的db、web都会被当作服务名处理。场景三compose up退出时自动 stop该命令还有一个容易被忽略的自动触发场景当前台运行的telepresence compose up未使用--detach被中断时runAttachedUp 会主动执行一次docker compose --file file [--profile ...] stop services确保依赖附件如 teleroute 网络、telemount 卷的容器被及时停止避免容器在附件断开后继续运行。源码注释明确解释了这样设计的原因直接杀掉compose up进程会导致容器 detach 后继续运行一段时间而其中部分容器依赖即将结束的附件且在 Windows 上compose up被中断后甚至完全不会停止容器。停止前需要了解的前置条件使用telepresence compose stop前应确认项目必须由telepresence compose up启动。stop作为生命周期命令其操作对象是那些通过 x-tele 扩展 建立了连接和附件的 compose 项目没有扩展服务的项目会被直接透传给底层docker compose stop见 run 中len(es) 0的分支。必须存在正在运行的 Telepresence daemon 连接。stop要求mustBeConnected true若 daemon 未运行且项目无扩展服务代码会回退为直接执行docker compose stop以产生符合预期的错误输出见 run 中的回退逻辑。附件卷提供者约束当只停止部分服务时runCommand 会校验 仍被引用的telemount卷是否由仍在运行范围内的扩展服务提供否则会报错提示volume ... is provided extended service ..., but that service is not included。与相关命令的配合telepresence compose up启动项目并建立附件是stop的对偶命令telepresence compose down彻底清理——停止并删除容器、结束附件、终止teleroute网络并退出 Telepresence。若只是临时暂停、稍后还要继续开发用stop更合适若要完全结束会话用downtelepresence quit退出客户端时若检测到 compose 项目在运行会自动代为执行compose down保证集群侧资源被释放。完整的x-tele扩展字段connections、mounts 以及 connect/proxy/ingest/intercept/replace/wiretap 六种服务扩展类型说明可继续阅读 docs/reference/compose.md可实际运行的示例配置位于 examples/compose 目录。赞分享云原生开发工具微服务网络【免费下载链接】telepresenceLocal development against a remote Kubernetes or OpenShift cluster项目地址https://gitcode.com/gh_mirrors/te/telepresence点击查看免费下载相关推荐uncloud uc stop 命令详解优雅停止集群中一个或多个服务uncloud uc stop 命令详解优雅停止集群中一个或多个服务 uc stop 是 uncloud 命令行工具中用于停止服务的核心命令它会把指定服务容器编排云原生运维后端网络微服务Telepresence compose pause 命令详解暂停 Compose 服务的完整指南Telepresence compose pause 命令详解暂停 Compose 服务的完整指南 telepresence compose pause 是云原生开发工具微服务网络Telepresence compose wait 命令详解等待 Compose 容器停止并管理项目生命周期Telepresence compose wait 命令详解等待 Compose 容器停止并管理项目生命周期 telepresence compose wai云原生开发工具微服务网络上一篇B站弹幕姬免费开源直播互动工具完整指南下一篇5分钟掌握音乐解锁技能让加密音乐重获自由播放权创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考