Docker架构及底层技术
  yyka2UPIbcp2 2023年11月02日 57 0

1Docker Engine

Docker Engine is a client-server application with these major components:

  • A server which is a type of long-running program called a daemon process (the dockerd command).
  • A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.
  • A command line interface (CLI) client (the docker command).

Docker Engine是具有以下主要组件的客户端-服务器应用程序:

  • 服务器是一种长期运行的程序,称为守护程序进程( dockerd命令)。
  • REST API,它指定程序可以用来与守护程序进行通信并指示其操作的接口。(https://blog.csdn.net/qq_42611547/article/details/84346809)
  • 命令行界面(CLI)客户端(docker命令)。

Docker架构及底层技术_API

The CLI uses the Docker REST API to control or interact with the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the underlying API and CLI.

The daemon creates and manages Docker objects, such as images, containers, networks, and volumes.

CLI使用Docker REST API通过脚本或直接CLI命令控制或与Docker守护程序交互。许多其他Docker应用程序都使用基础API和CLI。

守护程序创建和管理Docker对象,例如图像,容器,网络和卷。

2Docker architecture

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface.

Docker架构及底层技术_API_02

2.1The Docker daemon

The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.

2.2The Docker client

The Docker client (docker) is the primary way that many Docker users interact with Docker. When you use commands such as docker run, the client sends these commands to dockerd, which carries them out. The docker command uses the Docker API. The Docker client can communicate with more than one daemon.

2.3Docker registries

A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry.

When you use the docker pull or docker run commands, the required images are pulled from your configured registry. When you use the docker push command, your image is pushed to your configured registry.

2.4Docker 架构笔记:

2.4.1.Docker架构

   Docker使用了C/S体系架构。主要由Docker守护程序(docker daemon即dockerd)、Docker客户端(docker client即docker)、Docker注册表(docker registry)组成。

侦听Docker API请求并管理Docker对象,例如图像,容器,网络和卷。守护程序还可以与其他守护程序通信以管理Docker服务。

是许多Docker用户与Docker交互的主要方式。当您使用诸如之类的命令时docker run,客户端会将这些命令发送到dockerd,以执行这些命令。该docker命令使用Docker API。Docker客户端可以与多个守护程序通信。

   Docker注册表:存储Docker映像。Docker Hub是任何人都可以使用的公共注册表,并且默认情况下,Docker已配置为在Docker Hub上查找映像。您甚至可以运行自己的私人注册表。

                             使用docker pulldocker run命令时,所需的图像将从配置的注册表中提取。使用该docker push命令时,会将映像推送到配置的注册表。

2.4.2.Docker对象

   有很多,比如镜像、容器、网络,卷,插件和其他对象等等。

   image:镜像。An image is a read-only template with instructions for creating a Docker container. 

                一个镜像是一个包含了如何构建一个docker容器的只读模板。

                创建自己的镜像:

  •   docker提供了很多基础镜像,你可以在基础镜像的基础上commit新东西,生成新镜像提交上去。同时,docker使用了镜像分层的技术,新的commit会产生新的层,可以复用一部分老的层。这样一来制作新镜像的速度还是挺快的。
  •   docker还可以使用dockfile。Dockerfile是由一系列命令和参数构成的脚本。简单来说:Dockerfile是镜像的源码。dockerfile记录了镜像的制作步骤,即描述一个镜像是如何构建出来的。Dockerfile中的每条指令都会在映像中创建一个层(layer)。当您更改Dockerfile并重建映像时,仅重建那些已更改的层。与其他虚拟化技术相比,这是使映像如此轻巧,小型和快速的部分原因。
    使用docker build命令就可以根据dockfile文件构建镜像,docker会按照里面的步骤一步步把镜像构建好。在真正的项目中,是把dockerfile也放在项目的源码中,一起提交。这样只要有源码,就知道怎么打镜像了。而且从dockerfile中还可以知道项目的依赖环境和运行方式。所以,dockerfile其实是提供了项目运行起来的环境信息。            

   container:A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create

                     a new image based on its current state.

                    容器是图像的可运行实例。您可以使用Docker API或CLI创建,启动,停止,移动或删除容器。您可以将容器连接到一个或多个网络,将存储连接到它,甚至根据其当前状态创建一个新映像。

                    默认情况下,容器与其他容器及其主机之间的隔离度相对较高。您可以控制容器的网络,存储或其他基础子系统与其他容器或与主机的隔离程度。

                    容器由其映像以及在创建或启动时为其提供的任何配置选项定义。删除容器后,未存储在永久性存储中的状态更改将消失。

   service:没看懂,看懂再说把

3The underlying technology

Docker is written in the Go programming language and takes advantage of several features of the Linux kernel to deliver its functionality.

3.1Namespaces

Docker uses a technology called namespaces to provide the isolated workspace called the container. When you run a container, Docker creates a set of namespaces for that container.

These namespaces provide a layer of isolation. Each aspect of a container runs in a separate namespace and its access is limited to that namespace.

Docker Engine uses namespaces such as the following on Linux:

  • The pid namespace: Process isolation (PID: Process ID).
  • The net namespace: Managing network interfaces (NET: Networking).
  • The ipc namespace: Managing access to IPC resources (IPC: InterProcess Communication).
  • The mnt namespace: Managing filesystem mount points (MNT: Mount).
  • The uts namespace: Isolating kernel and version identifiers. (UTS: Unix Timesharing System).

3.2Control groups

Docker Engine on Linux also relies on another technology called control groups (cgroups). A cgroup limits an application to a specific set of resources. Control groups allow Docker Engine to share available hardware resources to containers and optionally enforce limits and constraints. For example, you can limit the memory available to a specific container.

3.3Union file systems

Union file systems, or UnionFS, are file systems that operate by creating layers, making them very lightweight and fast. Docker Engine uses UnionFS to provide the building blocks for containers. Docker Engine can use multiple UnionFS variants, including AUFS, btrfs, vfs, and DeviceMapper.

联合文件系统或UnionFS是通过创建图层进行操作的文件系统,使其非常轻便且快速。Docker Engine使用UnionFS为容器提供构建模块。Docker Engine可以使用多个UnionFS变体,包括AUFS,btrfs,vfs和DeviceMapper。

3.4Container format

Docker Engine combines the namespaces, control groups, and UnionFS into a wrapper called a container format. The default container format is libcontainer. In the future, Docker may support other container formats by integrating with technologies such as BSD Jails or Solaris Zones.

Docker Engine将名称空间,控制组和UnionFS组合到一个称为容器格式的包装器中。默认容器格式为libcontainer。将来,Docker可以通过与BSD Jails或Solaris Zones等技术集成来支持其他容器格式。

2.突然整这么多名词,看得我一懵一懵的,就理解到的程度总结一下,也可能就理解的不对

Docker架构及底层技术_docker_03

 

 图片摘自https://blog.csdn.net/sdulibh/article/details/84379853

  • docker engine,是docker的核心,主要有三个组成部分:dockerd、cli、restapi。cli就是docker命令,restapi就是可以解析cli命令,传递并指示dockerd去工作,dockerd接受到指示后去进行相应的操作,比如创建和管理Docker对象,例如图像,容器,网络和卷。
  • docker client,就是docker客户端,你可以在docker clent执行docker命令,比如docker run、docker pull等。docker client会解析命令并收集完参数后发一个http请求包docker daemon
  • docker damon,就是docker守护进程,其中包含了两个部分:
  • 一个是docker server,用于处理docker client的请求,包括了http server、route和handler。http server接受到docker client的请求以后就发给mut route,mut route根据请求的内容,选择对应的handler来执行该请求。
  • 一个是engine,是docker的运行引擎,也是核心模块。server的handler里存储了特定job的处理访问方法,engine接收到handler后,会根据要求执行job。
  • job是docker engine的最基本的工作执行单元。docker的每一个操作都会抽象成一个job被执行。这个job就像一个进程,有名称,有环境变量,有输入输出,有错误信息等等。
  • Driver,驱动模块,docker有三个驱动模块:graphdriver、networkdriver、execdriver,分别负责镜像、网络、容器管理。
  • graphdriver,负责已下载的镜像的管理。它有一个构建在SQLite之上的小型图数据库,用于管理镜像。主要工作内容:
  • 去docker registry下载镜像
  • 保管已下载的镜像(会为已下载的镜像设置对应的id)
  • 记录已下载镜像的各种关系(镜像与container的关系,关于每一个的容器镜像,具体存储的信息有:该容器镜像的元数据,容器镜像的大小信息,以及该容器镜像所代表的具体rootfs)。详细可参考:https://blog.csdn.net/tanzhe2017/article/details/81010495
  • networkdriver,负责container网络环境的配置。补充一下,Docker网络模式有Bridge模式、Host模式、Container模式、None模式(其中container模式非内置)。具体可参考https://www.cnblogs.com/zuxing/articles/8780661.html、https://www.jianshu.com/p/22a7032bb7bd。当创建一个容器是,可以指定你想要的网络模式,默认是Bridge模式主要工作内容:
  • docker启动时,为docker创建内置网络模式
  • container创建时,为container创建专属的虚拟网卡,为container分发ip地址、端口并做好与宿主机的端口映射、为container设置防火墙策略等。
  • execdriver,容器的执行驱动,负责创建容器运行的命名空间、容器资源使用的统计与限制、容器内部进程的真正运行。有两种实现方式,一个是LXC驱动,一个是native驱动,现在默认使用native,里面封装了libcontainer。
  • libcontainer,单独列出来,是因为networkdriver和execdriver的工作实际都是通过libcontainer实现的。libcontainer可以直接访问内核中与容器相关的API,来操纵namespace,cgroups,appamor,网络设备及防火墙策略等。
  • docker container, Docker架构中服务交付的最终体现形式。Docker按照用户的需求与指令,订制相应的Docker容器:
    * 用户通过指定容器镜像,使得Docker容器可以自定义rootfs等文件系统;
    * 用户通过指定计算资源的配额,使得Docker容器使用指定的计算资源;
    * 用户通过配置网络及其安全策略,使得Docker容器拥有独立且安全的网络环境;
    * 用户通过指定运行的命令,使得Docker容器执行指定的工作。
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论