docker 多架构接口数据交换

ops/2024/10/25 16:02:23/

前言

docker 的仓库支持一个 tag 下多个架构镜像, 这是如何实现的呢? 抓包看看其数据交互流程

前提

错误处理

执行命令buildx报错:

ERROR: Multi-platform build is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.
Learn more at https://docs.docker.com/go/build-multi-platform/

修复: 执行命令docker buildx create --use desktop-linux . 参考链接

OCI参考文档

构建

Dockerfile:

FROM hub.hujingnb.com/hj-public/debianRUN date > /tmp/date.txt

构建命令:

docker buildx build --platform linux/amd64,linux/arm64 -t hub.hujingnb.com/hj-public/test1:new --push .

抓包接口调用(2张图连续的, 1张图放不下了):

image-20241018145931938

image-20241018150006086

接口调用说明:

method接口说明OCI 对应
HEAD/v2/hj-public/debian/manifests/latest判断远端此镜像是否存在(每个架构)/v2/<name>/manifests/<reference>
GET/v2/hj-public/debian/manifests/sha256:520ce6d85...获取镜像 manifests(多架构的). 内容参考: 多架构manifest/v2/<name>/manifests/<reference>
GET/v2/hj-public/debian/manifests/sha256:d15e83b3...获取镜像 manifests(每个架构. 内容参考: 镜像manifests/v2/<name>/manifests/<reference>
GET/v2/hj-public/debian/blobs/sha256:8ea8...获取上一步拿到的所有 blob/v2/<name>/blobs/<digest>
中间步骤和普通的镜像上传一样. 可参考之前的文章
HEAD/v2/hj-public/test1/manifests/new判断远端 manifests 是否存在./v2/<name>/manifests/<reference>
PUT/v2/hj-public/test1/manifests/new上传manifests. 内容参考: 多架构manifest/v2/<name>/manifests/<reference>

至此, 一次多架构镜像构建并上传就完成了.

手动创建 manifests

我们也可以手动创建多架构, 而不是用 buildx. 命令如下:

# 假设仓库中已经存在: image:amd64 image:arm64 2个镜像
docker manifest create --insecure --amend  image:new image:arm64 image:amd64
docker manifest annotate image:new image:arm64 --os=linux --arch=arm64
docker manifest annotate image:new image:amd64 --os=linux --arch=amd64
docker manifest push --insecure --purge image:new

此时的接口调用, 直接跳到上面的最后2步: HEAD/PUT manifests接口.

拉取

其实在上一步构建的时候已经能够看到拉取的接口调用了. 在每次构建的时候, 要把不同架构的基础镜像拉倒本地进行构建.

这里就简单放一张接口调用流程, 命令: docker pull --platform=linux/arm64 hub.hujingnb.com/hj-public/test1:new:

image-20241018161603623

总结

单独镜像的推拉, 可以参考之前的文章

可以看到, 实现多架构时, 与非多架构镜像的唯一区别, 就是额外加了一个 manifests 类型, 用来将单架构镜像整合为多架构.

附件

架构manifest
{"schemaVersion": 2,"mediaType": "application/vnd.oci.image.index.v1+json","manifests":[{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:b4df0c22aa74c1aa7e1941619c4c63b2e3b1b1dc57436ecc6515e547b6888dab","size": 481,"platform":{"architecture": "386","os": "linux"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:651dd02a84abdd528e35e73d483aec5c361078bf169919bd3dac7bfe66d19290","size": 481,"platform":{"architecture": "amd64","os": "linux"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:9dac568c16fc9d22304b66eb1be48e849c912c0c1f233b7c8233eee5834fc082","size": 481,"platform":{"architecture": "arm","os": "linux","variant": "v5"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:e30e0f9e2580058251db6012e2886fa8b3971d980ae04c0d2e304190df601b4a","size": 481,"platform":{"architecture": "arm","os": "linux","variant": "v7"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:d15e83b3662501593be46a5a2aef02c2f5b4a1826aa5bef8cd21e7047a497af8","size": 481,"platform":{"architecture": "arm64","os": "linux"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:bddc1b85037e49dcbeef083c2b2868c73e23d7443e3c13bc177762b90ddaf80f","size": 481,"platform":{"architecture": "mips64le","os": "linux"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:e0d4150147fe4f2ecaf11fd532bd3d707d8632024f6743da58141b122a305887","size": 481,"platform":{"architecture": "ppc64le","os": "linux"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:ed6e2e64d1f0a99ca795c481ca08ff62fc8e1efca022ae22c5604bb27e6c76c1","size": 481,"platform":{"architecture": "s390x","os": "linux"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:785cf1dd62c0b02ce1fbf6cf615ef6eba5d4087385613ddcf26c221daac8e6a0","size": 566,"annotations":{"vnd.docker.reference.digest": "sha256:b4df0c22aa74c1aa7e1941619c4c63b2e3b1b1dc57436ecc6515e547b6888dab","vnd.docker.reference.type": "attestation-manifest"},"platform":{"architecture": "unknown","os": "unknown"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:520be2ba49e9d29e94745580f96858c3960f5fcf1eaa2b8b6e2574d5bba4bc91","size": 566,"annotations":{"vnd.docker.reference.digest": "sha256:651dd02a84abdd528e35e73d483aec5c361078bf169919bd3dac7bfe66d19290","vnd.docker.reference.type": "attestation-manifest"},"platform":{"architecture": "unknown","os": "unknown"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:edbe0bc83fdd4b6516399b43dcb4422c9b5e78a1a485fc8870554b7f1b59a501","size": 566,"annotations":{"vnd.docker.reference.digest": "sha256:9dac568c16fc9d22304b66eb1be48e849c912c0c1f233b7c8233eee5834fc082","vnd.docker.reference.type": "attestation-manifest"},"platform":{"architecture": "unknown","os": "unknown"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:3d456f67aef005b6da1b9ae91c778314b6d79553917d7d37e6aa484eb8ea5a91","size": 566,"annotations":{"vnd.docker.reference.digest": "sha256:e30e0f9e2580058251db6012e2886fa8b3971d980ae04c0d2e304190df601b4a","vnd.docker.reference.type": "attestation-manifest"},"platform":{"architecture": "unknown","os": "unknown"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:fe2aa90b281550a68cdc80208979c65acf8f64ca7ba709fe07fc38ed4eae7400","size": 566,"annotations":{"vnd.docker.reference.digest": "sha256:d15e83b3662501593be46a5a2aef02c2f5b4a1826aa5bef8cd21e7047a497af8","vnd.docker.reference.type": "attestation-manifest"},"platform":{"architecture": "unknown","os": "unknown"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:5308441e25778d9e467114c998ed3faf9c4bc18df17702fdbe7fcf495ff44eb9","size": 566,"annotations":{"vnd.docker.reference.digest": "sha256:bddc1b85037e49dcbeef083c2b2868c73e23d7443e3c13bc177762b90ddaf80f","vnd.docker.reference.type": "attestation-manifest"},"platform":{"architecture": "unknown","os": "unknown"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:264d85222bd6ff7a724dd33fa5071e6c3e1a30361989d52f2f7ca191ac7b9b20","size": 566,"annotations":{"vnd.docker.reference.digest": "sha256:e0d4150147fe4f2ecaf11fd532bd3d707d8632024f6743da58141b122a305887","vnd.docker.reference.type": "attestation-manifest"},"platform":{"architecture": "unknown","os": "unknown"}},{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:8f06e8c4e23717acbe73a0cd2f6ef9678b0c8c0387d67f7e604c85d43ba22cbf","size": 566,"annotations":{"vnd.docker.reference.digest": "sha256:ed6e2e64d1f0a99ca795c481ca08ff62fc8e1efca022ae22c5604bb27e6c76c1","vnd.docker.reference.type": "attestation-manifest"},"platform":{"architecture": "unknown","os": "unknown"}}]
}

其中后面几个 annotations 类型的内容, 是每个架构下的 manifests 证明文件. 用于镜像签名.

镜像manifests
{"schemaVersion": 2,"mediaType": "application/vnd.oci.image.manifest.v1+json","config": {"mediaType": "application/vnd.oci.image.config.v1+json","digest": "sha256:fe997a1b6216319619839e4ffe4bf083b70e58e751d5a26837254dc113b743f6","size": 579},"layers": [{"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip","digest": "sha256:c1e0ef7b956a07c7b090256aa16cbb0550a34d0625d1d23c5b1a76e92a58d01e","size": 49584978}]
}

http://www.ppmy.cn/ops/128379.html

相关文章

第 5 章 Kafka 消费者

5.1 Kafka 消费方式 5.2 Kafka 消费者工作流程 5.2.1 消费者总体工作流程 5.2.2 消费者组原理 5.2.3 消费者重要参数 5.3 消费者 API 5.3.1 独立消费者案例&#xff08;订阅主题&#xff09; package com.atguigu.kafka.consumer;import org.apache.kafka.clients.consume…

从零学习大模型(六)-----LoRA(上)

LoRA简介 LoRA&#xff08;Low-Rank Adaptation&#xff09;是一种参数高效的微调技术&#xff0c;旨在降低微调大规模预训练模型的存储和计算成本。**其核心思想是通过对模型的特定参数进行低秩分解&#xff0c;仅对少量附加参数进行训练&#xff0c;从而完成任务适应&#x…

证明在由特定矩阵生成的幺半子群中,存在收敛序列的子序列,其元素也能分别构成收敛序列

设 H H H是 G L 4 ( R ) GL_4(\mathbb{R}) GL4​(R)的由矩阵 ( 1 a 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ) , ( 1 0 0 0 0 1 b 0 0 0 1 0 0 0 0 1 ) , ( 1 0 0 0 0 1 0 0 0 0 1 c 0 0 0 1 ) \begin{pmatrix}1&a&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&…

Linux内核常见的网络丢包场景分析,零基础入门到精通,收藏这一篇就够了

摘要 一个数据包在网络中传输的过程中&#xff0c;是没法保证一定能被目的机接收到的。其中有各种各样的丢包原因&#xff0c;今天来学习一下数据包经过 linux 内核时常见的丢包场景。 1 收发包处理流程 有必要再回顾下 linux 内核的收发包处理流程&#xff0c;才能更好的认清…

pytorch nn.NLLLoss和nn.CrossEntropyLoss函数区别

nn.CrossEntropyLoss(交叉熵损失函数) 和nn.NLLLoss (负对数似然损失函数)的区别 输入格式&#xff1a; nn.CrossEntropyLoss&#xff1a;直接接受未归一化的 logits 作为输入&#xff0c;并在内部自动应用 log_softmax 来计算对数概率。nn.NLLLoss&#xff1a;接受对数概率&a…

【分布式微服务云原生】《Redis 分布式锁的挑战与解决方案及 RedLock 的强大魅力》

《Redis 分布式锁的挑战与解决方案及 RedLock 的强大魅力》 摘要&#xff1a; 本文深入探讨了使用 Redis 做分布式锁时可能遇到的各种问题&#xff0c;并详细阐述了相应的解决方案。同时&#xff0c;深入剖析了 RedLock 作为分布式锁的原因及原理&#xff0c;包括其多节点部署…

孤岛架构在异构性方面优势

1. 技术多样性 支持多种技术栈&#xff1a;孤岛架构允许每个孤岛使用最适合其业务需求的技术栈。这意味着可以根据不同的业务功能或数据处理需求选择不同的编程语言、数据库、框架和工具。 2. 独立性 独立开发和部署&#xff1a;每个孤岛可以独立开发和部署&#xff0c;这使…

docker 资源限制+调优详解

容器资源限制介绍 下面我将详细讲解 Docker 的各种资源限制及其在生产环境中的实际应用案例。我们将逐一探讨 CPU、内存、磁盘 I/O 和网络带宽的限制&#xff0c;并提供具体的配置示例和解释。 1. CPU 限制 1.1 设置 CPU 份额 --cpu-shares&#xff1a;设置容器的 CPU 优先…