认识
官网:https://opencontainers.org/
文档:https://specs.opencontainers.org/image-spec/ | The OpenContainers Image Spec
仓库:https://github.com/opencontainers/image-spec
容器镜像,Container Image,其是种轻量级、可移植的软件打包格式,其用于在容器化平台上部署应用程序,其包含运行应用程序所需的所有文件、依赖项、配置信息。简而言之,其类似于“绿色”、“便携”、“解压即可运行,无需安装依赖”的应用,极大简化应用的部署过程。
组成
镜像名称
docker pull | Docker Documentation
Where can I find the sha256 code of a docker image? – Stack Overflow
[registry/][username/]repository-name[:tag][@digest]
registry/ | 主机名,可选
- 别名:registry-hostname, repository
- 作用:指定镜像所在的 Docker Registry 地址,默认是 docker.io(即 Docker Hub)。
username/ | 用户名或组织名,可选
- 别名:namesapce, project
- 作用:在 Docker Hub 中,表其所属的用户或组织。如果省略,Docker 会使用 library/(官方镜像)。在 Harbor 中,则为 project 术语,表其所属的项目。所以,其本质功能是类似的。
repository-name | 仓库名称,必选
- 别名:image_name
- 作用:镜像的基本名称,通常代表软件或应用名称。
tag | 标签,可选
- 标识镜像的版本,默认是 latest。
- 最大长度:未知
- 允许字符:
digest | 摘要 | DIGEST
- 作用:基于镜像内容的唯一哈希值(SHA256),比 tag 更精确,确保拉取的是特定构建。digest 是镜像的唯一身份,不会被修改(而 tag 会被修改),通过 digest 能够获取确定版本的镜像;
- 但是,当 docker tag 后,不同仓库地址的 Digest 不同;
补充说明,针对我们的场景,我们接触 Helm Chart 较多,其习惯使用 registry repository tag digest 词汇。
平台字段的命名规范(platform)
The formatting for the platform specifier is defined in
https://github.com/containerd/containerd/blob/v1.2.6/platforms/platforms.go#L63
性质
- 可移植性:容器镜像可以在不同的容器化平台上运行,无需重新配置或修改应用程序。
- 轻量级:容器镜像只包含应用程序所需的最小文件和依赖项,因此它们比传统的虚拟机镜像更小巧。
- 可重复性:容器镜像是以声明式方式构建的,因此可以确保在不同环境中以相同的方式运行应用程序。
- 高效性:由于容器镜像使用分层文件系统,它们可以共享共同的层,从而节省存储空间并提高部署效率。
构建
—— 根据我们描述事物的方法,该部分将记录获得镜像的方法。
通过指令来构建镜像
kaniko | Build Images In Kubernetes | 其用于在容器或 Kubernetes Cluster 中从 Dockerfile 构建容器镜像。
- https://github.com/GoogleContainerTools/kaniko
- This repository was archived by the owner on Jun 3, 2025. It is now read-only. | https://github.com/GoogleContainerTools/kaniko/issues/3348
Docker Build | Use Docker to build Docker images,
Buildah | A tool that facilitates building OCI images. | https://github.com/containers/buildah
Podman to run Docker commands, | https://docs.gitlab.com/runner/executors/docker/#use-podman-to-run-docker-commands
Podman with GitLab Runner on Kubernetes instead.
保存镜像到本地
DeepSeek / 在没有 docker 服务的情况下,如何下载镜像
自动有了网络加速,我们再也不担心镜像拉取失败的问题。但是,有些客户网络隔离无法访问外网,因此需要我们下载并复制镜像到服务器。
该部分将记录:传输容器镜像的常用方法,例如,如何下载镜像到本地,复制到内网服务器,并加载镜像到本地。
docker save
crane pull
skopeo copy docker://nginx:latest dir:./nginx-image
应用
开发人员可以使用镜像来构建、部署和管理容器化应用程序,从而实现快速、可靠和可扩展的应用程序交付。