我们去看一下 [2.7M] data 这个文件,其他文件估计是一些 json 文本用于保存元数据信息。使用 file 命令查看 blobs/sha256/cb/cbdbe7a5bc2a134ca8ec91be58565ec07d037386d1f1d8385412d224deafca08 目录下的 data 文件。镜像的每一层都是存放在一个 64 位长度名称的文件夹下,文件名就是 data 。而且这个文件还是个 gzip 压缩后的文件。我么可以使用 tar 命令将其解压开来。
1 2 3 4 5
cd registry/v2/blobs/sha256/cb/cbdbe7a5bc2a134ca8ec91be58565ec07d037386d1f1d8385412d224deafca08 sh-4.2# file data data: gzip compressed data sh-4.2# mkdir layer sh-4.2# tar -xvf data -C layer/
将其解压到 layer 目录下,使用 tree 命令看一下文件夹下的内容就会明白,这不就是我们的 alpine 镜像真实的内容嘛😂。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
sh-4.2# tree -L 1 -d layer layer |-- bin |-- dev |-- etc |-- home |-- lib |-- media |-- mnt |-- opt |-- proc |-- root |-- run |-- sbin |-- srv |-- sys |-- tmp |-- usr `-- var
/ # skopeo --help NAME: skopeo - Various operations with container images and container image registries USAGE: skopeo [global options] command [command options] [arguments...] VERSION: 0.1.40 COMMANDS: copy Copy an IMAGE-NAME from one location to another inspect Inspect image IMAGE-NAME delete Delete image IMAGE-NAME manifest-digest Compute a manifest digest of a file standalone-sign Create a signature using local files standalone-verify Verify a signature using local files help, h Shows a list of commands or help for one command
真是一波三折啊,绕了一圈最终还是亲自指挥 build 一份吧,不过这个 build 过程也很简单。
1 2 3 4 5
git clone https://github.com/containers/skopeo skopeo cd !$ git checkout v1.0.0 make binary-static DISABLE_CGO=1 cp skopeo /usr/bin/
在这里需要注意一点,如果汝想构建一个在各 Linux 发行版通用的二进制可执行文件,一定要使用 make binary-static DISABLE_CGO=1 ,之前我没有仔细看文档直接 make 一把梭,然后在 Ubuntu 上构建出来的二进制执行文件拿到 CentOS 上去用,当场翻车提示以下错误:
1
skopeo: error while loading shared libraries: libdevmapper.so.1.02.1: cannot open shared object file: No such file or directory
# 加上 DISABLE_CGO=1 编译后的二进制可执行文件 ldd skopeo_s # not a dynamic executable
usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Various operations with container images and container image registries
Usage: skopeo [command]
Available Commands: copy Copy an IMAGE-NAME from one location to another delete Delete image IMAGE-NAME help Help about any command inspect Inspect image IMAGE-NAME list-tags List tags in the transport/repository specified by the login Login to a container registry logout Logout of a container registry manifest-digest Compute a manifest digest of a file standalone-sign Create a signature using local files standalone-verify Verify a signature using local files sync Synchronize one or more images from one location to another
skopeo version 1.0.0 commit: bd162028cd83ceecd8915736f2d66d5ca73ee54a
可以看到 skopeo 的功能很简单:
copy:复制一个镜像从 A 到 B,这里的 A 和 B 可以为本地 docker 镜像或者 registry 上的镜像。
Most commands refer to container images, using a transport:details format. The following formats are supported:
containers-storage:*docker-reference* An image located in a local containers/storage image store. Both the location and image store are specified in /etc/containers/storage.conf. (Backend for Podman, CRI-O, Buildah and friends)
dir:*path* An existing local directory path storing the manifest, layer tarballs and signatures as individual files. This is a non-standardized format, primarily useful for debugging or noninvasive container inspection.
docker://*docker-reference* An image in a registry implementing the “Docker Registry HTTP API V2”. By default, uses the authorization state in either $XDG_RUNTIME_DIR/containers/auth.json, which is set using (skopeo login). If the authorization state is not found there, $HOME/.docker/config.json is checked, which is set using (docker login).
docker-archive:*path[:*docker-reference*] An image is stored in the docker save formatted file. *docker-reference is only used when creating such a file, and it must not contain a digest.
docker-daemon:*docker-reference* An image docker-reference stored in the docker daemon internal storage. docker-reference must contain either a tag or a digest. Alternatively, when reading images, the format can be docker-daemon:algo:digest (an image ID).
oci:*path:tag* An image tag in a directory compliant with “Open Container Image Layout Specification” at path.