docker load and build过程的一些步骤理解

这篇具有很好参考价值的文章主要介绍了docker load and build过程的一些步骤理解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

docker load 命令执行原理

“docker load” command, the following steps are followed to load an image from a specified tar file to the local image repository:

  1. Parsing the tar file: Docker first parses the tar file to check its integrity and verify the format.
  2. Extracting the files: If the parsing is successful, Docker will extract the layers of the image and its metadata to a local temporary directory.
  3. Importing the image: After extraction, Docker reads the metadata from the tar file, including the configuration information of the image and the contents of each layer.
  4. Creating and loading the image layers: Based on the metadata, Docker creates each layer of the image one by one and loads them into the local image repository.
  5. Creating the image and applying labels: Once all the layers of the image are loaded, Docker creates the image based on the configuration information in the metadata and applies corresponding labels to the image.
  6. Cleaning up temporary files: After loading is complete, Docker cleans up the extracted files in the local temporary directory.

基本说明

"docker load"命令用于将本地文件中的镜像加载到Docker中。它接受一个tar文件作为参数,该文件包含了Docker镜像的所有层和元数据信息。

文件的分层处理指的是Docker镜像的构建过程中,每个步骤都会生成一个层(layer)。每个层都包含了文件系统的一部分,例如文件、目录和权限等。这些层构成了Docker镜像的文件系统。在加载镜像时,Docker会根据文件的顺序将这些层解压并组合在一起,以构建完整的镜像文件系统。

文件校验和是用于验证镜像文件的完整性的一种保证机制。每个层在构建时都会计算并生成一个校验和(checksum),用于表示该层的内容是否完整且无误。当使用"docker load"命令加载镜像时,Docker会比较镜像文件中的每个层的校验和和实际的文件内容,以确保文件的完整性和正确性。

总结起来,"docker load"命令将通过文件分层处理的方式将Docker镜像的文件系统解压并组合在一起,同时使用文件校验和来验证镜像文件的完整性和正确性。这样可以确保在加载镜像时获得完整、正确的镜像文件系统。

docker build 命令执行原理

The Docker build process is designed and integrated around the concept of file system abstraction. Docker provides a layered file system architecture that allows for efficient storage and retrieval of images and containers.

The file system abstraction in Docker is based on layers. Each layer represents a specific modification or addition to the file system. Layers can be created from a base image or from other layers, allowing for incremental changes and reusability.

During the Docker build process, a Dockerfile is used to define the steps required to build an image. Each step in the Dockerfile can modify or add files to the file system. Docker uses a technology called Union File System (UFS) to overlay these modifications on top of each other, creating a layered file system.

When building an image, Docker starts with a base image that serves as the initial layer. Each subsequent step in the Dockerfile will add a new layer on top of the previous ones. This layered approach allows for efficient image sharing and reuse, as layers that are already present in the system can be reused when building new images.

Docker also uses a copy-on-write strategy to optimize the use of storage. When a container is created from an image, only the differences between the container and the image are stored, rather than creating a complete copy. This allows for efficient use of disk space and faster container startup times.

docker --platform 参数说明

使用–platform参数可以构建跨平台的Docker镜像。
–platform参数接受一个格式为os/arch的字符串,例如linux/arm表示ARM架构。您可以使用这个参数来指定要构建的镜像支持的操作系统和架构。

Starting from Docker 19.03 version, the --platform parameter is supported. This parameter is used to specify on which platform the container should run. With the --platform parameter, you can specify that a container should run on a specific operating system architecture, such as linux/arm64 (ARM architecture) or linux/amd64 (x86 architecture).

The --platform flag is useful when you are working with multi-architecture environments or when you want to ensure that a container runs on a specific hardware platform. By specifying the platform with --platform, Docker will select the appropriate image or build context for that platform and run the container accordingly.

For example, if you have a Dockerfile that has specific instructions for ARM-based systems, you can specify --platform linux/arm64 when building the image. This tells Docker to select the appropriate base image and ensure that the resulting container runs on ARM64 architecture.

To summarize, the --platform flag in Docker allows you to specify on which platform your containers should run, ensuring compatibility and portability across different architectures.

Docker 构建过程的分层

Docker 构建过程的分层设计思想源于 Linux 内核的 union fs(联合文件系统),它将多个文件系统合并为一个单一的文件系统,从而实现对多个文件系统的管理。在 Docker 中,这种分层设计可以有效地管理和组织镜像的各个层次,使得镜像的大小得到优化,同时也提高了镜像的构建和加载速度。

在 Docker 构建过程中,每个指令都会创建一个新的镜像层,并添加到基础镜像中。这些层可以被看作是镜像的一个个切片,每个切片都包含了一组文件和目录。这种分层设计使得镜像的构建过程更加灵活和可扩展,因为我们可以根据需要添加或删除层,而不需要重新构建整个镜像。

在 Docker 镜像加载过程中,Docker 会从底层开始,依次加载每一层。每一层都会被加载到一个独立的文件系统中,这些文件系统会被合并为一个单一的文件系统,然后挂载到容器的根文件系统中。这样,我们就可以在容器内部访问到镜像中的所有文件和目录。

这种分层设计和加载过程使得 Docker 镜像具有很高的灵活性。我们可以根据需要修改或删除镜像的任何部分,而不需要重新构建整个镜像。同时,由于每个层都被加载到一个独立的文件系统中,因此即使某个层出现问题,也不会影响到其他层,从而确保了镜像的完整性。

Linux 内核的 union fs(联合文件系统)

Linux内核的union fs(联合文件系统)是一种特殊的文件系统,它可以将多个目录结合起来,形成一个单一的逻辑目录。每个目录可以是一个独立的文件系统,称为原始文件系统。联合文件系统会将这些原始文件系统层叠在一起,并提供一个单一的视图。

联合文件系统的主要功能是将不同的目录树合并为一个统一的目录。当用户在联合文件系统的目录中进行读写操作时,实际上是对底层原始文件系统进行读写操作。这使得用户可以在单一的目录结构中同时访问不同的文件系统,而不需要切换到不同的目录。

联合文件系统的核心思想是使用层叠挂载(stacked mount)来实现。在创建联合文件系统时,可以指定多个原始文件系统,并指定它们在层次结构中的顺序。各个原始文件系统按照指定的顺序进行挂载,形成一棵层次结构的目录树。当进行文件操作时,联合文件系统会按照层次结构从上到下逐层搜索对应的文件。

联合文件系统还提供了一些特殊的操作方式,如只读模式挂载、白名单挂载和黑名单挂载。这些操作方式可以根据用户的需求来控制对原始文件系统的读写权限。

总体而言,联合文件系统是一种非常有用的文件系统技术,可以简化文件系统的管理和使用。它在容器技术中得到广泛应用,可以将多个容器的文件系统层叠在一起,实现资源隔离和快速部署。

层叠挂载(stacked mount)

层叠挂载(stacked mount)是指在计算机系统中将一个文件系统挂载到另一个文件系统上的过程。这种挂载方式允许将多个文件系统层叠在一起,形成一个逻辑上统一的文件系统层级结构。

通过层叠挂载,可以将不同类型的文件系统组合在一起,使其共同作为一个整体可访问的文件系统。这样做的一个常见应用是将一个网络文件系统(NFS、CIFS等)挂载到本地文件系统上,使远程文件系统中的文件和目录在本地文件系统中以普通文件和目录的形式可见。

在层叠挂载中,挂载的文件系统称为上层文件系统,被挂载的文件系统称为下层文件系统。上层文件系统中的访问操作会经过上层文件系统的处理,然后传递到下层文件系统中进行具体的操作。这样,上层文件系统就可以给下层文件系统提供额外的功能,如加密、压缩、快照等。

层叠挂载的一个重要特性是透明性,即上层文件系统对下层文件系统的存在是透明的,上层文件系统的用户无需关注下层文件系统的细节。用户只需要在上层文件系统中进行操作,而无需关心实际文件和目录所在的具体位置。

层叠挂载还可以通过挂载选项进行灵活配置。例如,可以选择以只读模式挂载下层文件系统,或者将下层文件系统的某个子目录挂载到上层文件系统的特定位置等。

总之,层叠挂载提供了一种灵活和强大的文件系统管理方式,允许在计算机系统中灵活组合和扩展文件系统,提供更高级别的文件系统功能。

SHA256 在docker中的设计和集成思想

The primary design and integration principles of SHA256 in Docker are as follows:

  1. Security: SHA256 is a cryptographic hash function that ensures data integrity and security. It is used to generate a unique hash value for the contents of a Docker image or a layer. This makes it easier to verify the authenticity and integrity of the image or layer.
  2. Content Addressing: Docker uses SHA256 as a content addressing mechanism. Each layer of an image is identified by its SHA256 hash, which means if the content of a layer changes, the hash will change as well. This allows Docker to quickly determine if any changes have been made to an image or a layer.
  3. Immutable Images: Docker promotes the use of immutable images, meaning that their contents cannot be modified once they are built. SHA256 plays a key role in enforcing immutability by ensuring that the hash of an image or a layer remains consistent.
  4. Layered Architecture: Docker uses a layered architecture, where each layer represents a change or modification to an existing image. The SHA256 hash is used to uniquely identify and reference each layer, allowing Docker to efficiently utilize caching and deduplication techniques.
  5. Integrating with Container Runtime: Docker integrates SHA256 with its container runtime to ensure that the image being run is the same as the one that was built. The runtime checks the hash of the image and its layers before execution to validate its integrity and prevent any tampering.

SHA-256在Docker中的设计思想主要包括以下几个方面:

  1. 安全性:SHA-256是一种加密哈希算法,它具有很高的安全性。在Docker中,每个镜像和容器都有一个唯一的SHA-256标识符,该标识符是使用镜像内容计算得出的哈希值。通过SHA-256标识符,可以确保镜像和容器的内容完整性,并防止篡改。
  2. 基于内容寻址:Docker中的镜像都是通过内容寻址来访问的,这意味着每个镜像的位置和访问方式都是根据其SHA-256标识符来确定的。这种设计使得镜像可以追溯到其原始内容,而不是依赖于特定的位置或名称。
  3. 冗余删除:SHA-256标识符可以用于确定镜像是否存在于本地,并在不同的Docker主机之间进行镜像的复制和分享。当多个Docker主机之间存在相同的镜像时,只需在其中一个主机上保存一份镜像,其他主机可以通过SHA-256标识符来引用该镜像,避免了冗余的存储。
  4. 版本控制:由于每个镜像都有唯一的SHA-256标识符,Docker可以轻松管理和控制镜像的版本。当对一个镜像进行更改时,会生成一个新的SHA-256标识符,并与原始版本进行区分。这使得可以方便地进行版本回滚和管理。

Docker image ID

Docker image ID is generated based on the image’s content and metadata using a cryptographic hash function called SHA256.

When a new Docker image is created, Docker examines the content and metadata of the image, including the filesystem layers, the image configuration, and any other information relevant to the image. It then applies the SHA256 algorithm to this data to generate a unique 64-character hexadecimal identifier.

This process ensures that each image has a unique identifier that effectively represents its content. Any changes made to the content or metadata will result in a different image ID. This allows Docker to efficiently identify and track images, as well as determine if two images are identical or different.


Docker Image ID 是由 Docker 根据镜像的描述文件在本地计算生成的,用于在 imagedb 数据库中作为目录名称。Docker 镜像 ID 保存在 /var/lib/docker/image/overlay2/imagedb/content/sha256 目录下,以 sha256sum 计算文件内容得出的哈希值命名。

具体而言,Image ID 是根据镜像的配置信息(config)计算得出的,该信息包含在镜像的 JSON 描述文件中。Docker 使用这些配置信息来计算 Image ID,以确保每个镜像都有唯一的 ID。计算 Image ID 的具体步骤并未明确,但可以确定的是,它是基于镜像内容(包括配置信息和各层的 diffID)进行哈希计算的结果。因此,即使镜像的内容完全相同,计算出的 Image ID 也会相同。

当拉取新的镜像时,Docker 会重新计算 Image ID,如果本地已经存在相同的 Image ID,则会直接使用本地已有的镜像,而不会再次下载。这样可以提高效率并避免重复下载相同的镜像。

总之,Docker Image ID 是根据镜像的配置信息和各层内容通过哈希算法计算得到的唯一标识符,用于在 Docker 中管理镜像。

docker 中的安全机制和参数

Docker内置了一系列安全机制,这些机制有助于保护容器和宿主机的安全。在设计--security参数时,Docker考虑了以下几个内置的安全机制:

  1. 命名空间隔离:Docker使用命名空间来隔离容器的进程、网络、文件系统和其他资源,以避免容器之间的相互影响。
  2. 控制组(cgroups):Docker利用cgroups来限制容器对系统资源的访问和使用,通过设置资源限制,可以防止容器过度消耗主机资源。
  3. 安全标签:Docker通过安全标签(SELinux或AppArmor)来控制容器的访问权限,防止容器越权访问主机上的敏感资源。
  4. 用户命名空间:Docker使用用户命名空间,将容器内的特权用户映射到宿主机上的非特权用户,从而减少特权容器对主机的影响。
  5. 容器镜像验证:Docker支持通过签名和校验镜像的手段,以确保镜像的完整性和来源的真实性。这样可以避免运行恶意或被篡改的镜像。

综上所述,--security参数的设计考虑了Docker内置的一些安全机制,以提供额外的灵活性和控制,以满足特定场景下的需求。用户可以根据自身情况,权衡安全性和便利性,并选择相应的安全配置。文章来源地址https://www.toymoban.com/news/detail-722931.html

到了这里,关于docker load and build过程的一些步骤理解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • ROS 2 colcon build报错SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip

    我们在ROS 2 中使用colcon build时,出现以下问题 SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. 我们可以尝试运行构建完毕的程序,是否能正常执行(或者我们可以使用以下指令把ROS2/examples 拉下来测试一下) 依旧colcon build ,依旧出现这样

    2024年02月15日
    浏览(41)
  • 在Unity中一些Loading界面制作的小技巧

    目录 1.使用自己的图片制作游戏开始、加载界面。 2.制作加载进度条并且实现场景跳转 3.制作简单计时器并且实现场景跳转 添加Canvas,image,Rawimage. 将图片导入到Unity中,可以创建一个文件夹保存它们,直接拖拽进来即可。(图片拖拽到Rawimage上,就会显示图片) 首先先添加场

    2024年01月16日
    浏览(32)
  • ARM汇编【3】:LOAD/STORE MULTIPLE PUSH AND POP

          有时一次加载(或存储)多个值更有效。为此,我们使用LDM(加载多个)和STM(存储多个)。这些指令有一些变化,基本上只在访问初始地址的方式上有所不同。这是我们将在本节中使用的代码。我们将一步一步地研究每一条指令。         在开始之前,请记住.字指

    2024年02月11日
    浏览(25)
  • tensorflow 2.16.1 can not use save and load

    already use model.save(). not use the load weight. the question is : self.b1 = BatchNormalization(), in my code, the BatchNormalization(), do not take any parameter, why Layer \\\'batch_normalization_20\\\' expected 4 variables? Sent by you: already use model.save(). not use the load weight. the question is : self.b1 = BatchNormalization(), in my code, the BatchNo

    2024年04月26日
    浏览(20)
  • PyTorch翻译官网教程8-SAVE AND LOAD THE MODEL

    Save and Load the Model — PyTorch Tutorials 2.0.1+cu117 documentation 在本节中,我们将了解如何通过保存、加载和运行模型预测来持久化模型状态。 PyTorch模型将学习到的参数存储在一个名为state_dict的内部状态字典中。这些可以通过 torch.save 方法持久化 输出 要加载模型权重,需要首先创

    2024年02月16日
    浏览(29)
  • 关于VS code ESP-IDF 提示“loading ‘build.ninja‘: 系统找不到指定的文件” 的解决方案

    最近在搞一个开源项目玩,需要用IDF编译工程,奈何之前没用过IDF,只好自己装一下,又不想放弃VS code的便捷;后面发现VS code可以支持IDF平台,就在VS code中安装了;如何安装不再本文赘述,网上很多博客可以参考;本文仅阐述如何将工程编译并下载到设备; 将工程在Vs code I

    2024年02月02日
    浏览(43)
  • diffusers-Load pipelines,models,and schedulers_diffusers 加载safetensors

    先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7 深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前! 因此收集整理了一份《2024年最新大数据全套学习资料》,

    2024年04月27日
    浏览(21)
  • Your build is currently configured to use Java 17.0.6 and Gradle 5.6.4.

    报错信息 错误原因 因为项目所需的gradle5.6.4对应的是java8,而Android Studio Flamingo | 2022.2.1 Patch 1自带的java版本为17,它会使用默认的java版本去编译项目,所以编译时导致报错。 解决方法 1、安装jdk1.8:Win10如何安装JDK1.8,最快最详细教程 2、安装并配置好环境后,输入命令查看

    2024年02月11日
    浏览(28)
  • Building AI-Copilot:构建 LLM 支持的生成应用程序的一些经验教训和模式

    我们正在构建一个用于产品策略和生成创意的实验性人工智能副驾驶,名为“Boba”。一路上,我们学到了一些关于如何构建此类应用程序的有用经验,我们已经根据模式制定了这些应用程序。这些模式允许应用程序帮助用户更有效地与大语言模型 (LLM) 交互,编排提示以获得

    2024年02月14日
    浏览(35)
  • Android Your build is currently configured to use Java 17.0.6 and Gradle 6.5.

    Android 项目报错 原因:是因为 Java 版本和 Gradle 版本不匹配,可以调节 Java 版本或者 Gradle 版本,但是改动 Gradle 风险比较大,有可能会导致其他问题,所以推荐修改 Java 版本,如果熟练可以忽略随便调整。 当前报错意思是:当前编译配置是 Java 17.0.6 ,如果需要使用这个版本

    2024年02月19日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包