20、Docker基础知识-manifest

引子

docker pull centos@sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d
sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d: Pulling from library/centos
193bcbf05ff9: Pull complete 
Digest: sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d
Status: Downloaded newer image for centos@sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d
docker.io/library/centos@sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d

# 这个DigestDigest: sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d 代表的是什么?

 docker images --digests | grep centos
 centos                                            v1                  sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d   8c52f2d0416f        22 months ago       175MB

# sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d 和 8c52f2d0416f区别

image 组成

一个image由manifestimage index (可选)filesystem layersImage COnfig四部分组成,对应的关系图如下
在这里插入图片描述
如下只讨论ImageIndex ,imagemanifest,Imageconfig

imageIndex 和 Imagemanifest 是一对多的关系
imagemanifest 和 imageconfig 是一对一的关系

拉取镜像的流程

第一步:找到ImageIndex(里面由manifests 列表,找到manifest)
第二步:找到manifest
第三步:下载imageconfig 和 layers
通过docker manifest inspect busybox:latest 命令看下的 ImageIndex 文件格式

{
    
    
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
   "manifests": [ // manifest集合,可能是arm 架构,也可能是amd架构,等等,下载镜像会检测匹配
      {
    
    
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 527,
         "digest": "sha256:99243e861067446c9aed305b5690cccb88658d23af3fde338398f27386ded1be", // 这个就是manifest文件的指纹
         "platform": {
    
    
            "architecture": "amd64", // amd64架构
            "os": "linux"  // 适用于linux 系统
         }
      }
      ...
   ]
}

来看下manifest.json文件的格式(随便找的一个格式,和busybox上述版本不一致)。

Digest: sha256:9fd67116449f225c6ef60d769b5219cf3daa831c5a0a6389bbdd7c952b7b352d 这个值就是这个manifest.json做的sha256sum 的指纹值
{
    
    
    "layers": [
        {
    
    
            "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
            "digest": "sha256:8ddc19f16526912237dd8af81971d5e4dd0587907234be2b83e249518d5b673f", //这个是各个层对应的文件
            "size": 667590
        }
    ],
    "schemaVersion": 2,
    "config": {
    
    
        "mediaType": "application/octet-stream",
        "digest": "sha256:a77dce18d0ecb0c1f368e336528ab8054567a9055269c07c0169cba15aec0291", // 这个就是我们的镜像Id ,就是image confg 对应的文件
        "size": 1459
    },
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json"
}

拉取镜像文件在哪里

docker pull busybox@sha256:99243e861067446c9aed305b5690cccb88658d23af3fde338398f27386ded1be

docker images ls | grep busy
busybox                                           <none>              a77dce18d0ec        5 days ago          1.24MB

docker images --digests | grep busybox
busybox                                           <none>              sha256:99243e861067446c9aed305b5690cccb88658d23af3fde338398f27386ded1be   a77dce18d0ec        5 days ago          1.24MB

# 注意此时mamifest.json文件对应的指纹为:99243e861067446c9aed305b5690cccb88658d23af3fde338398f27386ded1be
# 对应的imageid a77dce18d0ec

cd /var/lib/docker/image/overlay2
vim repositories.json 
# 主要看下面这段,我们要找到imgeid
    "busybox": {
    
    
      "busybox@sha256:99243e861067446c9aed305b5690cccb88658d23af3fde338398f27386ded1be": "sha256:a77dce18d0ecb0c1f368e336528ab8054567a9055269c07c0169cba15aec0291"
    },
cd /var/lib/docker/image/overlay2/imagedb/content/sha256
# 找到 a77dce18d0ecb0c1f368e336528ab8054567a9055269c07c0169cba15aec0291 文件,对这个文件做sha256sum 得到就是a77dce18d0ecb0c1f368e336528ab8054567a9055269c07c0169cba15aec0291  这个就是imageid

总结

Image Index 就是manifest 的集合

manifest 记录了image config 和 layers

猜你喜欢

转载自blog.csdn.net/weixin_43443216/article/details/112179797