> This option file is used in:

> This option file is used in: 容器运行时云原生CLI【免费下载链接】podmanPodman: A tool for managing OCI containers and pods.项目地址https://gitcode.com/gh_mirrors/po/podman点击查看免费下载#### podman build, farm build, manifest push, push即该选项由四个命令共享。在 cmd/podman 目录中可以找到各命令对它的注册 - podman push[push.go](https://link.gitcode.com/i/99b104751b414ae1a636067c45d2c012) 通过 flags.StringVar(pushOptions.CompressionFormat, compFormat, compressionFormat(), compression format to use) 注册并挂载补全函数 common.AutocompleteCompressionFormat - podman manifest push[manifest/push.go](https://link.gitcode.com/i/83f777243f940fe8aa77930197ac5cc2) 同样注册该选项 - podman build 与 podman farm build通过 [common/build.go](https://link.gitcode.com/i/338992bc89bc8f351cd282b5832eef42) 在构建参数解析时读取该标志。 此外shell 补全函数在 [common/completion.go](https://link.gitcode.com/i/2353889b3242f60d7a58693cfa79a4c3) 中明确列出了可补全的三个合法取值 go func AutocompleteCompressionFormat(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { types : []string{gzip, zstd, zstd:chunked} return types, cobra.ShellCompDirectiveNoFileComp }因此在交互式 shell 中输入podman push --compression-format TAB即可获得这三种格式的自动补全。二、支持的取值与默认值2.1 三种取值选项的完整语法定义为--compression-formatgzip | zstd | zstd:chunked取值说明典型适用场景gzip传统的 gzip 压缩兼容性最好几乎所有 registry 与运行时都支持通用推送、跨平台分发、与旧工具链协作zstdFacebook 开源的 Zstandard 压缩压缩/解压速度更快、同级别压缩率更优追求推送速度与体积平衡的现代环境zstd:chunked基于 zstd 的分块压缩格式支持服务端按需解压、延迟解压lazy decompression等增强能力与支持该格式的 registry如 Quay配合使用时2.2 默认值gzip但可被 containers.conf 覆盖文档明确指出The default isgzipunless overridden in the containers.conf file.这一默认值链路在源码中清晰可见。在 push.go 中func compressionFormat() string { if registry.IsRemote() { return } return containerConfig.ContainersConfDefaultsRO.Engine.CompressionFormat }也就是说本地模式--compression-format的默认值取自containers.conf的engine.compression_format配置项未配置时该字段为空最终解析回退为gzip远程模式podman-remote或服务端模式默认值为空字符串由服务端按其配置决定。2.3 在 containers.conf 中全局覆盖用户可以通过containers.conf统一修改默认压缩格式无需在每个命令上加参数。仓库中附带的默认配置模板位于 vendor/go.podman.io/common/pkg/config/containers.conf# The compression format to use when pushing an image. # Valid options are: gzip, zstd and zstd:chunked. # This field is ignored when pushing images to the docker-daemon and # docker-archive formats. It is also ignored when the manifest format is set # to v2s2. # zstd:chunked is incompatible with encrypting images, and will be treated as zstd with a warning # in that case. # #compression_format gzip配置示例写入$HOME/.config/containers/containers.conf或/etc/containers/containers.conf[engine] compression_format zstd需要注意模板注释中补充的两个重要限制推送到docker-daemon与docker-archive目标格式时该配置被忽略因为这些格式内部固定使用 gzip 层manifest 格式为v2s2时同样忽略该配置。podman build一侧的读取逻辑在 common/build.go} else { algo, err : compression.AlgorithmByName(podmanConfig.ContainersConfDefaultsRO.Engine.CompressionFormat) if err ! nil { return nil, fmt.Errorf(parsing compression_format from containers.conf: %w, err) } ... }可见如果containers.conf中配置了非法值构建会直接报错并指明来源是compression_format解析失败。三、zstd:chunked与镜像加密的不兼容处理文档对zstd:chunked给出了一条明确警告zstd:chunkedis incompatible with encrypting images, and will be treated aszstdwith a warning in that case.即当你在podman push --encryption-key ... --compression-format zstd:chunked这样的组合中使用分块压缩时Podman 不会直接报错终止而是打印一条警告信息静默地将压缩格式降级为普通zstd继续推送。这是因为zstd:chunked依赖服务端对镜像层的分块解析能力而加密后的层内容无法被 registry 端识别与按需解压二者在功能上互斥。相同的行为约束也原样写入了containers.conf的模板注释见上文第 486-487 行保证命令行与配置文件两条路径的行为一致。四、与相邻选项的交互规则4.1 自动联动--force-compression--force-compression的官方说明见 force-compression.md规定Defaults totrueif--compression-formatis explicitly specified on the command-line,falseotherwise.对应实现位于 push.goif cmd.Flags().Changed(compression-format) { if !cmd.Flags().Changed(force-compression) { // If compression-format is set and no value for --force-compression // is selected then defaults to true. pushOptions.ForceCompressionFormat true } }podman manifest push的 manifest/push.go 中实现了完全相同的逻辑。这意味着只要你显式指定了--compression-formatPodman 就会强制以该格式重新压缩并覆盖目标上已有的其他格式变体确保推送出去的层一定是你指定的压缩格式若目标 registry 已存在同层不同压缩格式的 blob也不会复用旧 blob 而直接以新格式写入。4.2 与--compression-level配合--compression-level用于指定压缩级别取值范围与格式强相关可从 scp_compression_test.go 的测试用例侧面印证格式与级别的范围校验逻辑gzip合法范围1-9默认 5zstd合法范围1-20默认 3级别超出对应格式范围会直接报错例如对gzip传 10 会得到 “compression level 10 is out of range for gzip, must be between 1 and 9”。两个选项可以同时使用如podman push --compression-format zstd --compression-level 10 myimage quay.io/example/myimage:latest4.3 与--disable-compression互斥在构建场景中--compression-format不能与--disable-compression同时使用。common/build.go 会在两者同时出现时直接返回错误if c.Flag(disable-compression).Changed flags.DisableCompression { if c.Flag(compression-format).Changed { return nil, errors.New(--disable-compression and --compression-format cannot be used together) } ... }原因很直观一个选项要求禁用压缩另一个选项要求指定压缩算法语义互相矛盾Podman 选择在参数校验阶段就拒绝该组合。五、易混淆点podman image scp的压缩选项需要特别提醒podman image scp也有自己的--compression-format选项但它不共享本选项的取值集合。从 scp.go 可以看到其合法值来自utils.ScpCompressionValues()根据 podman-image-scp.1.md其取值仅为gzip、zstd与none默认none即按podman save的原始形态传输。相关测试 scp_compression_test.go 明确断言zstd:chunked对podman image scp是不接受的{ name: zstd:chunked is not accepted, opts: entities.ScpCompressionOptions{CompressionFormat: zstd:chunked}, // c/image knows this one, podman image scp deliberately does not. wantErr: unsupported compression format zstd:chunked, },因此在查阅文档或编写脚本时务必区分两种语境构建/推送/清单推送使用的是本文所述的gzip | zstd | zstd:chunked镜像传输image scp则只支持gzip | zstd | none。六、快速上手与推荐实践# 1. 显式使用 zstd 压缩推送级别 10 podman push --compression-format zstd --compression-level 10 myimage quay.io/example/myimage:latest # 2. 使用 zstd:chunked需目标 registry 支持且不能与镜像加密同时使用 podman push --compression-format zstd:chunked myimage quay.io/example/myimage:latest # 3. 构建镜像时指定压缩格式 podman build --compression-format zstd -t myimage . # 4. 全局默认改为 zstd写入 containers.conf 的 [engine] 段 # compression_format zstd赞分享容器运行时云原生CLI【免费下载链接】podmanPodman: A tool for managing OCI containers and pods.项目地址https://gitcode.com/gh_mirrors/po/podman点击查看免费下载相关推荐 This option file is used in:This option file is used in: podman build, podman container.unit.5.md.in, create容器运行时云原生CLIThis is testThis is test script console.log 2333 /script 若页面中检测到 Vue executeScript 默认即为 t前端文档开发工具This is a test repo.This is a test repo. This repo includes some c codes. readme refactor 分支下的自述文件文档知识库教育教程创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考