镜像底层原理¶
一 背景¶
镜像仓库功能
- 镜像分发:并对外提供一套,HTTP API V2
- 镜像存储:镜像仓库中的所有镜像,都是以数据块 (Blob) 的方式存储在文件系统中。文件系统
以下内容均针对镜像仓库存储在文件系统中进行展开。
同一镜像,在不同的镜像仓库中,存储方式和内容完全一样。
二 测试¶
2.1 测试环境¶
- harbor
registry:redhatxl.com 对应地址:1x.xx.xx
namespace:harbor-reg
repository:mycentos
docker push redhatxl.com/harbor-reg/REPOSITORY[:TAG]
- 腾讯云
appid: 12xxxxxxxxxx30',
secret_id: AKxxxxxxxxxxxxx
secret_key: kFUTDxxxxxxxxxxxxxxxxxE0Xq
仓库名称:anchnet-devops-common-test
镜像地址:ccr.ccs.tencentyun.com/anchnet-devops-common-test/base-node
用户名:xxxxxxxxx5
密码:5xxxxxxxxxx
docker login --username=xxxxxxxxxx1875 -p 51idc.qcloudhub ccr.ccs.tencentyun.com
2.1 获取镜像manifests¶
[root@img-tools imgtools]# curl -X GET redhatxl.com/v2/harbor-reg/base-python36/manifests/latest -uadmin:redhatxl
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 7709,
"digest": "sha256:ed6ab02f968c4b4b6c3b98f4461e6c2cbf7c639cc611295190784674ee7dcd3e"
},
"layers": [
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 75863188,
"digest": "sha256:75f829a71a1c5277a7abf55495ac8d16759691d980bf1d931795e5eb68a294c0"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 93,
"digest": "sha256:a16d96b1c51534d0fdb3ca64e89b49d272b274cc4370a23fd6e93f653d2ae992"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 144,
"digest": "sha256:2f746b711ecd754fb510a5ebef61e604869e461b8813a24dd2104f5644e700a6"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 500,
"digest": "sha256:83bd569a87758935e0112c2c590de3c308f811b74139c03a32255aaf22ae3975"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 490259,
"digest": "sha256:a6286d6173c0992e8b5ef0ca3d384195f63e6b4649e9566a41c31809c352d25a"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 314,
"digest": "sha256:9cd506705b843a77101c1fd074d1217f42b70eda499dc2ca64c23aaf44552c6d"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 17909802,
"digest": "sha256:f4ca1980898549f7c6e3d8ce4005b25d4e52221a577b15b50836361f099f2872"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 30362969,
"digest": "sha256:ac70bee47a24a8af762ed5b2f9075b491a974b8c38151198a076911d60bff3c5"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 127,
"digest": "sha256:400b472f0ac1b04330cbd352e17293dbfef46cc94803c862a966989bfc85cfd8"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 1117,
"digest": "sha256:12f4adb3b6429a963b92d117cfb26606d17b9b49d1c4686b0382b32a810d8450"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 55047070,
"digest": "sha256:0a5360ec0e5db590ed9781c2d34ca61edb0df961a0e004f586d63594d35d583c"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 75009416,
"digest": "sha256:7652672f85b542bbf717656a78cc905965f53b84acdc2586826c1452d704bf85"
}
]
}
- 获取config
{"architecture":"amd64","config":{"Hostname":"5f91842eb6f8","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","SS_AGENT_VERSION=3.22.0","START_SIGSCI=0","PYTHON_PIP_VERSION=19.0.3","NR_MOD_VERSION=4.14.0.115","SS_MOD_VERSION=1.2.0","BASE_ROOT=/data","LC_ALL=zh_CN.utf8","LANG=zh_CN.utf8","LANGUAGE=zh_CN.utf8"],"Cmd":["/bin/bash"],"ArgsEscaped":true,"Image":"sha256:aa7aab57b6c571a732ef54e23b6e983859cc87866c2e84f739e50c84e6a3e0c5","Volumes":null,"WorkingDir":"/data","Entrypoint":null,"OnBuild":[],"Labels":{"maintainer":"kaliarch","org.label-schema.build-date":"20200809","org.label-schema.license":"GPLv2","org.label-schema.name":"CentOS Base Image","org.label-schema.schema-version":"1.0","org.label-schema.vendor":"CentOS","org.opencontainers.image.created":"2020-08-09 00:00:00+01:00","org.opencontainers.image.licenses":"GPL-2.0-only","org.opencontainers.image.title":"CentOS Base Image","org.opencontainers.image.vendor":"CentOS"}},"container":"4fc5294025a02c0083301fbb44f72ae6eeb89d1a4bb35173728a59d8fbb1860b","container_config":{"Hostname":"5f91842eb6f8","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","SS_AGENT_VERSION=3.22.0","START_SIGSCI=0","PYTHON_PIP_VERSION=19.0.3","NR_MOD_VERSION=4.14.0.115","SS_MOD_VERSION=1.2.0","BASE_ROOT=/data","LC_ALL=zh_CN.utf8","LANG=zh_CN.utf8","LANGUAGE=zh_CN.utf8"],"Cmd":["/bin/sh","-c","pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple \u0026\u0026 pip3 config set install.trusted-host mirrors.aliyun.com; pip3 install --upgrade pip \u0026\u0026 pip install --default-timeout=1000 -r ${BASE_ROOT}/requirements.txt --use-feature=2020-resolver"],"ArgsEscaped":true,"Image":"sha256:aa7aab57b6c571a732ef54e23b6e983859cc87866c2e84f739e50c84e6a3e0c5","Volumes":null,"WorkingDir":"/data","Entrypoint":null,"OnBuild":[],"Labels":{"maintainer":"kaliarch","org.label-schema.build-date":"20200809","org.label-schema.license":"GPLv2","org.label-schema.name":"CentOS Base Image","org.label-schema.schema-version":"1.0","org.label-schema.vendor":"CentOS","org.opencontainers.image.created":"2020-08-09 00:00:00+01:00","org.opencontainers.image.licenses":"GPL-2.0-only","org.opencontainers.image.title":"CentOS Base Image","org.opencontainers.image.vendor":"CentOS"}},"created":"2020-11-19T10:08:14.838692824Z","docker_version":"18.09.7","history":[{"created":"2020-08-10T18:20:08.948813347Z","created_by":"/bin/sh -c #(nop) ADD file:61908381d3142ffba798ae9a904476d19b197ab79d0338f14bec0f76649df8d4 in / "},{"created":"2020-08-10T18:20:09.298928893Z","created_by":"/bin/sh -c #(nop) LABEL org.label-schema.schema-version=1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20200809 org.opencontainers.image.title=CentOS Base Image org.opencontainers.image.vendor=CentOS org.opencontainers.image.licenses=GPL-2.0-only org.opencontainers.image.created=2020-08-09 00:00:00+01:00","empty_layer":true},{"created":"2020-08-10T18:20:09.474278304Z","created_by":"/bin/sh -c #(nop) CMD [\"/bin/bash\"]","empty_layer":true},{"created":"2020-10-31T18:26:27.646630099Z","created_by":"/bin/sh -c mkdir /meta"},{"created":"2020-10-31T18:26:30.135647485Z","created_by":"/bin/sh -c #(nop) ADD file:a378e744ad31356a19bb64e022e5945f43e49fede32ed700e2ae068417029dca in /meta/ "},{"created":"2020-10-31T18:26:32.620481323Z","created_by":"/bin/sh -c #(nop) ADD file:4bee920c5635620068033e111bc61656de4bfde96f261e315fb86df24c4bd694 in /meta/ "},{"created":"2020-10-31T18:32:15.062608026Z","created_by":"/bin/sh -c yum -y update \u0026\u0026 yum clean all"},{"created":"2020-10-31T18:32:17.053227485Z","created_by":"/bin/sh -c #(nop) ENV SS_AGENT_VERSION=3.22.0 START_SIGSCI=0","empty_layer":true},{"created":"2020-10-31T18:32:19.344841625Z","created_by":"/bin/sh -c #(nop) COPY file:7cb853b776c22e8cbde94576e69ac385a4c660581ae915b1a8c3c7554b638048 in /etc/yum.repos.d/ "},{"created":"2020-10-31T18:32:46.979408426Z","created_by":"/bin/sh -c yum -y install sigsci-agent-${SS_AGENT_VERSION} \u0026\u0026 yum clean all"},{"created":"2020-10-31T18:44:08.878827379Z","created_by":"/bin/sh -c #(nop) ENV PYTHON_PIP_VERSION=19.0.3 NR_MOD_VERSION=4.14.0.115 SS_MOD_VERSION=1.2.0","empty_layer":true},{"created":"2020-10-31T18:47:16.250803275Z","created_by":"/bin/sh -c yum -y install epel-release wget \u0026\u0026 yum -y install python36 python36-pip \u0026\u0026 yum clean all \u0026\u0026 python3 -m pip install --no-cache-dir --upgrade --force-reinstall \"pip==$PYTHON_PIP_VERSION\" \u0026\u0026 pip3 install --no-cache-dir virtualenv newrelic==${NR_MOD_VERSION} https://dl.signalsciences.net/sigsci-module-python/${SS_MOD_VERSION}/src/sigscimodule-${SS_MOD_VERSION}.tar.gz"},{"created":"2020-11-19T09:48:50.78298361Z","created_by":"/bin/sh -c #(nop) LABEL maintainer=kaliarch","empty_layer":true},{"created":"2020-11-19T09:48:51.211125932Z","created_by":"/bin/sh -c #(nop) ENV BASE_ROOT=/data LC_ALL=zh_CN.utf8 LANG=zh_CN.utf8 LANGUAGE=zh_CN.utf8","empty_layer":true},{"created":"2020-11-19T09:48:51.512365134Z","created_by":"/bin/sh -c #(nop) WORKDIR /data"},{"created":"2020-11-19T09:55:02.051276372Z","created_by":"/bin/sh -c #(nop) COPY file:ea79bd23fc6540bbf011dcec29c6db19273f19edc4563451814db971813fa791 in /data/ "},{"created":"2020-11-19T09:57:27.685569884Z","created_by":"/bin/sh -c mkdir /etc/yum.repos.d.bak \u0026\u0026 mv /etc/yum.repos.d/* /etc/yum.repos.d.bak/ \u0026\u0026 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo; curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo; yum makecache fast \u0026\u0026 yum install -y epel-release \u0026\u0026 yum install freetds-devel.x86_64 freetds.x86_64 tcping openssh-clients -y; localedef -c -f UTF-8 -i zh_CN zh_CN.utf8; rm -rf /usr/bin/python \u0026\u0026 ln -sv /usr/bin/python3 /usr/bin/python \u0026\u0026 ln -sv /usr/bin/python3 /usr/local/bin/python; /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \u0026\u0026 echo 'Asia/Shanghai' \u003e/etc/timezone"},{"created":"2020-11-19T10:08:14.838692824Z","created_by":"/bin/sh -c pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple \u0026\u0026 pip3 config set install.trusted-host mirrors.aliyun.com; pip3 install --upgrade pip \u0026\u0026 pip install --default-timeout=1000 -r ${BASE_ROOT}/requirements.txt --use-feature=2020-resolver"}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:613be09ab3c0860a5216936f412f09927947012f86bfa89b263dfa087a725f81","sha256:2dffb8082ab5202c664c374ecfb695a4adbf2f58bed6cb9e547dade04aebac1d","sha256:aca83ae8a3110c67d20fadb1fcebae7074ea89e02a73091c2f95474a280d7fd0","sha256:910a7d877245e11661934bde0c042784b83f91a86821b8411f316ce34f5f0093","sha256:2faae2dbe3820c570317a1ef78cad54950af13263333ed7d96f8a626117a8b31","sha256:765961673d6620fdd2b81bcf01407a43203792a275db0acd9f78ddae73c60953","sha256:3d439b32a94378eb09c8d599fd4a2238d51ea9e2e0d1ed0ea83a9d43e0327534","sha256:bf516cdb2791571140e2a7cc86fd978bb32b03f63162a35c74c05be2ae8511d0","sha256:8d8713e0c8fa85dff6382d267ded8faac409db4c7a805f6a5cc632f93f8f054b","sha256:398370fc331c4caadf15ce84dd22fb060b5426cc2d62e7e4018bb584d5ce6d6f","sha256:26012d3f82bbe4a64c9c8d16e4987c4875119fd2e9bcf56d9714c7d735c76170","sha256:7452610eee95c1fdcd38836334518b04ffffea1fc959ab9f5c7c41cd27241c2d"]}}
- 获取blob层
curl -X GET redhatxl.com/v2/harbor-reg/base-python36/blobs/sha256:7652672f85b542bbf717656a78cc905965f53b84acdc2586826c1452d704bf85 -uadmin:redhatxl
三 结论¶
- 通过 Registry API 获得的两个镜像仓库中相同镜像的 manifest 信息完全相同。
- 两个镜像仓库中相同镜像的 manifest 信息的存储路径和内容完全相同。
- 两个镜像仓库中相同镜像的 blob 信息的存储路径和内容完全相同。