Docker深入了解

0 总结

使用docker info查看docker运行细节,使用docker inspect查看容器运行细节。
containerd-shim 充当了容器运行时(rrunc是一个轻量级的进程容器运行时工具)与 containerd 之间的桥梁,承担了容器的创建、启动、停止和销毁等操作。

1 docker info

docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.10.5)
  compose: Docker Compose (Docker Inc., v2.18.1)

Server:
 Containers: 118
  Running: 96
  Paused: 0
  Stopped: 22
 Images: 112
 Server Version: 19.03.15
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: systemd
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.19.113-300.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 45.19GiB
 Name: 172-30-30-101
 ID: IXRP:MTDA:3XHX:CPCY:YQPP:7QEP:URNN:B2UY:H6EZ:DVHZ:EB2B:KEVC
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  0.0.0.0/0
  127.0.0.0/8
 Live Restore Enabled: true

WARNING: bridge-nf-call-ip6tables is disabled

上述输出是运行docker info命令后返回的结果。该命令用于查看Docker运行时环境的详细信息。

解释结果如下:

Client(客户端):

  • Context: 默认上下文。
  • Debug Mode: 调试模式已禁用。
  • Plugins: Docker安装的插件列表。包括buildx和compose插件。

Server(服务器):

  • Containers(容器): 当前有118个容器,其中96个正在运行,22个已停止。
  • Images(镜像): 当前有112个镜像。
  • Server Version(服务器版本): Docker服务器版本为19.03.15。
  • Storage Driver(存储驱动): 使用overlay2作为存储驱动。
  • Backing Filesystem(底层文件系统): 文件系统使用xfs。
  • Supports d_type: 应该是指文件系统支持d_type特性。
  • Native Overlay Diff: 指示是否启用了本机覆盖层差异(Overlay Diff)。
  • Logging Driver(日志驱动): 使用json-file作为日志驱动程序。
  • Cgroup Driver(Cgroup驱动): 使用systemd作为Cgroup驱动程序。
  • Plugins: Docker安装的插件列表。包括Volume、Network和Log等插件。
  • Swarm(集群): Swarm模式处于非活动状态。
  • Runtimes(运行时): Docker使用runc作为默认运行时。
  • Default Runtime(默认运行时): 默认情况下使用runc作为运行时。
  • Init Binary(初始二进制文件): Docker使用的初始化二进制文件为docker-init。
  • containerd version: containerd的版本信息。
  • runc version: runc的版本信息。
  • init version: 初始化程序的版本信息。
  • Security Options(安全选项): 安全选项中启用了seccomp,并使用默认配置文件。
  • Kernel Version(内核版本): 操作系统的内核版本为4.19.113-300.el7.x86_64。
  • Operating System(操作系统): 运行Docker的操作系统为CentOS Linux 7 (Core)。
  • OSType: 操作系统类型为Linux。
  • Architecture(架构): 主机架构为x86_64。
  • CPUs(CPU数量): 系统中有8个CPU。
  • Total Memory(总内存): 系统总内存为45.19GiB。
  • Name: 主机名为172-30-30-101。
  • ID: Docker分配给此主机的唯一ID。
  • Docker Root Dir(Docker根目录): Docker的根目录为/var/lib/docker。
  • Registry(镜像仓库): Docker镜像仓库为https://index.docker.io/v1/。
  • Labels(标签): Docker标签中没有设置任何值。
  • Experimental: 实验特性未启用。
  • Insecure Registries(不安全的镜像仓库): 允许从0.0.0.0/0和127.0.0.0/8这两个地址范围获取镜像。
  • Live Restore Enabled(实时恢复已启用): 可以进行实时容器恢复。

WARNING(警告):

  • bridge-nf-call-ip6tables被禁用。

2 docker inspect

该命令返回了关于名为"k8s_etcd_etcd-172-30-30-101_kube-system_ccee5f78fdd19a28e13a2a9c4f8ba7c5_0"的Docker容器的详细信息。

以下是一些重要字段的解释:

  • Id: 容器的唯一标识符。
  • Created: 容器创建的时间戳。
  • Path: 容器的入口点可执行文件路径。
  • Args: 传递给容器入口点的参数列表。
  • State: 容器的状态信息,包括运行状态、进程ID、退出代码等。
  • Image: 容器所使用的镜像的唯一标识符。
  • HostConfig: 容器的主机配置,包括挂载点、日志配置、网络模式等。
  • Mounts: 容器中挂载的文件系统路径。
  • Config: 容器的配置信息,包括主机名、环境变量、暴露的端口等。
  • NetworkSettings: 容器的网络设置,如IP地址、网关等。

请注意,此处提供的信息可能不完整,并且命令的输出已经进行了适当的格式化以便显示。

扫描二维码关注公众号,回复: 15729945 查看本文章
docker inspect k8s_etcd_etcd-172-30-30-101_kube-system_ccee5f78fdd19a28e13a2a9c4f8ba7c5_0
[
    {
    
    
        "Id": "76a3ff6175691b43aa67cedd3ff4f77ec47a1d3ed7a84990404b5ed88ee1e7e3",
        "Created": "2023-07-10T02:24:28.843493987Z",
        "Path": "etcd",
        "Args": [
            "--advertise-client-urls=https://172.30.30.101:2379",
            "--cert-file=/etc/kubernetes/pki/etcd/server.crt",
            "--client-cert-auth=true",
            "--data-dir=/opt/qfusion/etcd",
            "--initial-advertise-peer-urls=https://172.30.30.101:2380",
            "--initial-cluster=172-30-30-101=https://172.30.30.101:2380",
            "--key-file=/etc/kubernetes/pki/etcd/server.key",
            "--listen-client-urls=https://127.0.0.1:2379,https://172.30.30.101:2379",
            "--listen-metrics-urls=http://127.0.0.1:2381",
            "--listen-peer-urls=https://172.30.30.101:2380",
            "--name=172-30-30-101",
            "--peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt",
            "--peer-client-cert-auth=true",
            "--peer-key-file=/etc/kubernetes/pki/etcd/peer.key",
            "--peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt",
            "--snapshot-count=10000",
            "--trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt"
        ],
        "State": {
    
    
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 11220,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2023-07-10T02:24:28.982141892Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:303ce5db0e90dab1c5728ec70d21091201a23cdf8aeca70ab54943bbaaf0833f",
        "ResolvConfPath": "/var/lib/docker/containers/7e86d443879d6e8d735c3e119aa096c36e70fea03cdd9a1ab7ef8ee21756b599/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/7e86d443879d6e8d735c3e119aa096c36e70fea03cdd9a1ab7ef8ee21756b599/hostname",
        "HostsPath": "/var/lib/kubelet/pods/ccee5f78fdd19a28e13a2a9c4f8ba7c5/etc-hosts",
        "LogPath": "/var/lib/docker/containers/76a3ff6175691b43aa67cedd3ff4f77ec47a1d3ed7a84990404b5ed88ee1e7e3/76a3ff6175691b43aa67cedd3ff4f77ec47a1d3ed7a84990404b5ed88ee1e7e3-json.log",
        "Name": "/k8s_etcd_etcd-172-30-30-101_kube-system_ccee5f78fdd19a28e13a2a9c4f8ba7c5_0",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
    
    
            "Binds": [
                "/opt/qfusion/etcd:/opt/qfusion/etcd",
                "/etc/kubernetes/pki/etcd:/etc/kubernetes/pki/etcd",
                "/var/lib/kubelet/pods/ccee5f78fdd19a28e13a2a9c4f8ba7c5/etc-hosts:/etc/hosts",
                "/var/lib/kubelet/pods/ccee5f78fdd19a28e13a2a9c4f8ba7c5/containers/etcd/5b7af2e8:/dev/termination-log"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
    
    
                "Type": "json-file",
                "Config": {
    
    
                    "max-size": "100m"
                }
            },
            "NetworkMode": "container:7e86d443879d6e8d735c3e119aa096c36e70fea03cdd9a1ab7ef8ee21756b599",
            "PortBindings": null,
            "RestartPolicy": {
    
    
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "container:7e86d443879d6e8d735c3e119aa096c36e70fea03cdd9a1ab7ef8ee21756b599",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": -998,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "seccomp=unconfined"
            ],
            "UTSMode": "host",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 2,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "kubepods-besteffort-podccee5f78fdd19a28e13a2a9c4f8ba7c5.slice",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 100000,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/asound",
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
    
    
            "Data": {
    
    
                "LowerDir": "/var/lib/docker/overlay2/b47eed97a959e733f2f5583d689a884d4d8c73f510872b0b1ba429140b8a8d49-init/diff:/var/lib/docker/overlay2/2fb3706abf15c0aef48416ff665012d38d6c7692a16245ac570d14d1df3a8c9e/diff:/var/lib/docker/overlay2/18f09190247c06ef5cb98494b5919f94cedd3a38a1a822dcbe319447a456825f/diff:/var/lib/docker/overlay2/e11e2abdfe4bd69b64f42b9f127be980e3cd1491ef70ea8e3bb9420b4a8ffeef/diff",
                "MergedDir": "/var/lib/docker/overlay2/b47eed97a959e733f2f5583d689a884d4d8c73f510872b0b1ba429140b8a8d49/merged",
                "UpperDir": "/var/lib/docker/overlay2/b47eed97a959e733f2f5583d689a884d4d8c73f510872b0b1ba429140b8a8d49/diff",
                "WorkDir": "/var/lib/docker/overlay2/b47eed97a959e733f2f5583d689a884d4d8c73f510872b0b1ba429140b8a8d49/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
    
    
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/ccee5f78fdd19a28e13a2a9c4f8ba7c5/etc-hosts",
                "Destination": "/etc/hosts",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
    
    
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/ccee5f78fdd19a28e13a2a9c4f8ba7c5/containers/etcd/5b7af2e8",
                "Destination": "/dev/termination-log",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
    
    
                "Type": "bind",
                "Source": "/opt/qfusion/etcd",
                "Destination": "/opt/qfusion/etcd",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
    
    
                "Type": "bind",
                "Source": "/etc/kubernetes/pki/etcd",
                "Destination": "/etc/kubernetes/pki/etcd",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
    
    
            "Hostname": "172-30-30-101",
            "Domainname": "",
            "User": "0",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
    
    
                "2379/tcp": {
    
    },
                "2380/tcp": {
    
    },
                "4001/tcp": {
    
    },
                "7001/tcp": {
    
    }
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": null,
            "Healthcheck": {
    
    
                "Test": [
                    "NONE"
                ]
            },
            "Image": "sha256:303ce5db0e90dab1c5728ec70d21091201a23cdf8aeca70ab54943bbaaf0833f",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "etcd",
                "--advertise-client-urls=https://172.30.30.101:2379",
                "--cert-file=/etc/kubernetes/pki/etcd/server.crt",
                "--client-cert-auth=true",
                "--data-dir=/opt/qfusion/etcd",
                "--initial-advertise-peer-urls=https://172.30.30.101:2380",
                "--initial-cluster=172-30-30-101=https://172.30.30.101:2380",
                "--key-file=/etc/kubernetes/pki/etcd/server.key",
                "--listen-client-urls=https://127.0.0.1:2379,https://172.30.30.101:2379",
                "--listen-metrics-urls=http://127.0.0.1:2381",
                "--listen-peer-urls=https://172.30.30.101:2380",
                "--name=172-30-30-101",
                "--peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt",
                "--peer-client-cert-auth=true",
                "--peer-key-file=/etc/kubernetes/pki/etcd/peer.key",
                "--peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt",
                "--snapshot-count=10000",
                "--trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt"
            ],
            "OnBuild": null,
            "Labels": {
    
    
                "annotation.io.kubernetes.container.hash": "9fdc85e1",
                "annotation.io.kubernetes.container.restartCount": "0",
                "annotation.io.kubernetes.container.terminationMessagePath": "/dev/termination-log",
                "annotation.io.kubernetes.container.terminationMessagePolicy": "File",
                "annotation.io.kubernetes.pod.terminationGracePeriod": "30",
                "io.kubernetes.container.logpath": "/var/log/pods/kube-system_etcd-172-30-30-101_ccee5f78fdd19a28e13a2a9c4f8ba7c5/etcd/0.log",
                "io.kubernetes.container.name": "etcd",
                "io.kubernetes.docker.type": "container",
                "io.kubernetes.pod.name": "etcd-172-30-30-101",
                "io.kubernetes.pod.namespace": "kube-system",
                "io.kubernetes.pod.uid": "ccee5f78fdd19a28e13a2a9c4f8ba7c5",
                "io.kubernetes.sandbox.id": "7e86d443879d6e8d735c3e119aa096c36e70fea03cdd9a1ab7ef8ee21756b599"
            }
        },
        "NetworkSettings": {
    
    
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
    
    },
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
    
    }
        }
    }
]

3 ll /var/lib/docker目录

ll /var/lib/docker
总用量 104
drwx------   2 root root    24 7  10 10:06 builder
drwx--x--x   4 root root    92 7  10 10:06 buildkit
drwx-----x 120 root root 16384 7  14 15:27 containers
drwx------   3 root root    22 7  10 10:06 image
drwxr-x---   3 root root    19 7  10 10:06 network
drwx-----x 794 root root 69632 7  14 22:07 overlay2
drwx------   4 root root    32 7  10 10:06 plugins
drwx------   2 root root     6 7  10 10:17 runtimes
drwx------   2 root root     6 7  10 10:06 swarm
drwx------   2 root root     6 7  14 22:07 tmp
drwx------   2 root root     6 7  10 10:06 trust
drwx-----x   2 root root    25 7  10 10:06 volumes

以下是/var/lib/docker目录中各个子目录的作用:

  • builder:包含构建器相关的文件。
  • buildkit:包含BuildKit相关的文件。
  • containers:包含所有容器的相关信息和状态。
  • image:包含Docker镜像的相关信息和文件。
  • network:包含Docker网络的相关信息。
  • overlay2:使用overlay2存储驱动的容器层和镜像层。
  • plugins:包含Docker插件的相关文件。
  • runtimes:包含容器运行时的相关文件。
  • swarm:包含Swarm模式相关的文件。
  • tmp:临时文件夹,用于存放临时文件。
  • trust:包含信任相关的文件。
  • volumes:包含Docker卷的相关信息。

这些目录对于Docker运行时非常重要,它们存储了Docker的各种配置、容器、镜像等数据。

4 dockerd

/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

dockerd 是 Docker 的守护进程,负责管理和运行 Docker 容器。它是 Docker 引擎的核心组件之一,用于与用户交互,并处理关于容器的创建、启动、停止等操作。

以下是 dockerd 的一些关键功能:

  • 容器生命周期管理dockerd 负责创建、启动、停止和销毁容器。它能够监控容器的状态并及时做出相应的调整。

  • 镜像管理dockerd 提供了对 Docker 镜像的管理功能。它能够从远程仓库下载镜像,构建新的镜像并将其推送到仓库中。

  • 资源隔离dockerd 使用 Linux 内核提供的虚拟化技术(如命名空间和控制组)来实现容器的资源隔离。这使得多个容器可以在同一主机上并行运行而不会相互干扰。

  • 网络管理dockerd 管理容器的网络连接和配置。它为容器分配 IP 地址,并可与其他容器或外部网络进行通信。

  • 日志记录dockerd 可以收集容器的日志信息,并将其保存到本地或远程存储中,方便用户查看和分析。

除了上述功能之外,dockerd 还支持插件机制,可以通过安装和使用插件来扩展其功能。它还提供了一组丰富的命令行接口(CLI)和 API,使用户能够与 Docker 引擎进行交互,并管理容器和镜像。

注意:在大多数情况下,用户不直接与 dockerd 进行交互,而是通过 Docker CLI 或其他 Docker 相关工具来操作 Docker 引擎。

5 docker-containerd > crictl ctr

containerd

containerd 是一个开源的容器运行时工具,它是 Docker 引擎的一部分。它提供了一种标准的接口和功能,用于管理容器的生命周期、镜像管理、容器网络和存储等方面。

containerd 的设计目标是为了提供一个高度可靠、轻量级的容器运行时环境,以满足不同场景下的需求。它采用了模块化的架构,将各个功能划分为不同的组件,并通过 gRPC 接口进行通信。这使得用户可以根据自己的需求选择并使用所需的功能,而无需加载不必要的组件。

containerd 提供了一套强大的命令行工具和 API,使用户可以方便地创建、运行、暂停、恢复和删除容器。它还支持镜像拉取、导出和删除,允许用户在容器间共享和重用镜像。此外,containerd 还提供了网络插件系统,用于配置和管理容器之间的网络连接。

通过 containerd 的插件机制,用户可以扩展其功能,如添加新的容器运行时、存储后端或网络驱动程序。这使得 containerd 成为一个灵活且可定制的容器管理工具,适用于各种不同的使用案例和部署环境。

总之,containerd 是一个功能强大、稳定可靠的容器运行时工具,它提供了丰富的功能和灵活的架构,使得用户能够更有效地管理和运行容器化应用程序。

/var/lib/containerd/

/var/lib/containerd/ 目录下的各个子目录的中文介绍和作用如下:

  • io.containerd.content.v1.content: 该目录存储容器运行时使用的内容(例如镜像和文件系统层)。

  • io.containerd.metadata.v1.bolt: 该目录包含容器的元数据,使用 BoltDB 数据库进行存储。

  • io.containerd.runtime.v1.linux: 该目录是容器运行时的位置,主要存储 Linux 容器的运行时状态和信息。

  • io.containerd.runtime.v2.task: 该目录用于存储 v2 版本的容器任务相关的信息。

  • io.containerd.snapshotter.v1.native: 该目录是容器快照管理器的位置,使用本机快照器进行存储。

  • io.containerd.snapshotter.v1.overlayfs: 该目录是容器快照管理器的位置,使用 OverlayFS 快照器进行存储。

  • tmpmounts: 该目录用于挂载临时文件系统。

ll /run/containerd/

ll /run/containerd/ 命令用于查看 /run/containerd/ 目录下的文件和文件夹的详细信息。

根据您提供的输出,这是 /run/containerd/ 目录下的内容:

  • containerd.sock:这是一个 socket 文件,用于与 Containerd 守护进程通信。
  • containerd.sock.ttrpc:这也是一个 socket 文件,但使用了 ttrpc 协议进行通信。
  • io.containerd.runtime.v1.linux:这是一个文件夹,可能包含与 Containerd 运行时相关的文件。
  • io.containerd.runtime.v2.task:这是一个文件夹,可能包含与 Containerd 任务运行时相关的文件。
  • s:这是一个文件夹,其大小为 1960 字节。该文件夹可能包含其他与 Containerd 相关的文件或数据。

总的来说,/run/containerd/ 目录是容器运行时管理程序 Containerd 使用的目录,其中包含与容器运行时相关的文件和文件夹。

扩展
ttrpc(Tiny Transport RPC)协议是一种轻量级的远程过程调用(RPC)协议。它旨在提供高效、简洁的通信机制,使不同进程或设备之间能够进行可靠的通信并进行方法调用。以下是与其他协议相比,ttrpc协议的一些不同之处:

  1. 轻量级:ttrpc协议设计简洁,具有较小的开销,因此适用于嵌入式系统和资源受限的环境。

  2. 性能优化:ttrpc协议通过减少数据包的大小和数量来提高性能。它使用紧凑的二进制格式,并在不需要时避免冗余信息的传输。

  3. 支持多种传输层:ttrpc协议可以在不同的传输层上运行,例如TCP、UDP、UNIX域套接字等。这使得它更加灵活,适应各种网络环境。

  4. 可靠性:ttrpc协议提供了可靠的消息传递机制,确保消息的完整性和顺序性。它使用确认和重传机制来处理丢失或损坏的消息。

  5. 多语言支持:ttrpc协议具有多语言绑定,因此可以在不同编程语言中进行交互和使用。

总的来说,ttrpc协议是一种简洁、高效的轻量级RPC协议,具有较小的开销和灵活性,在资源受限的环境中提供可靠的通信机制。

RPC(Remote Procedure Call,远程过程调用)协议是一种用于不同计算机之间进行通信的协议。它允许一个计算机程序调用另一个计算机上的子程序或函数,就像调用本地程序一样。RPC协议隐藏了底层网络通信细节,使得远程调用看起来像是本地调用。

RPC协议的基本原理是通过客户端和服务器之间的通信来实现远程过程调用。客户端发送请求消息给服务器,服务器执行相应的操作,并将结果返回给客户端。RPC协议定义了消息的格式和交互方式,以确保正确的调用和响应。

以下是RPC协议的主要特点:

  1. 透明性:RPC协议隐藏了网络通信的复杂性,使得远程调用对开发者透明。开发人员可以像调用本地函数一样调用远程函数,无需关心底层的网络细节。

  2. 独立性:RPC协议独立于具体的编程语言和平台。这意味着可以使用不同的编程语言实现客户端和服务器,只需要遵循相同的RPC协议规范。

  3. 扩展性:RPC协议支持在分布式环境下扩展应用程序。可以将不同的功能模块部署在不同的计算机上,通过RPC协议进行通信,实现分布式计算。

  4. 安全性:RPC协议可以提供安全的通信方式。通过加密和认证等机制,可以确保通信的机密性和完整性。

常见的RPC协议包括XML-RPC、JSON-RPC和gRPC等。这些协议在数据编码格式、传输方式和性能等方面有所区别,开发人员可以根据具体需求选择合适的协议。

crictl

crictl -h
NAME:
   crictl - client for CRI

USAGE:
   crictl [global options] command [command options] [arguments...]

VERSION:
   v1.13.0

COMMANDS:
     attach        Attach to a running container
     create        Create a new container
     exec          Run a command in a running container
     version       Display runtime version information
     images        List images
     inspect       Display the status of one or more containers
     inspecti      Return the status of one or more images
     inspectp      Display the status of one or more pods
     logs          Fetch the logs of a container
     port-forward  Forward local port to a pod
     ps            List containers
     pull          Pull an image from a registry
     runp          Run a new pod
     rm            Remove one or more containers
     rmi           Remove one or more images
     rmp           Remove one or more pods
     pods          List pods
     start         Start one or more created containers
     info          Display information of the container runtime
     stop          Stop one or more running containers
     stopp         Stop one or more running pods
     update        Update one or more running containers
     config        Get and set crictl options
     stats         List container(s) resource usage statistics
     completion    Output bash shell completion code
     help, h       Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --config value, -c value            Location of the client config file (default: "/etc/crictl.yaml") [$CRI_CONFIG_FILE]
   --debug, -D                         Enable debug mode
   --image-endpoint value, -i value    Endpoint of CRI image manager service [$IMAGE_SERVICE_ENDPOINT]
   --runtime-endpoint value, -r value  Endpoint of CRI container runtime service (default: "unix:///var/run/dockershim.sock") [$CONTAINER_RUNTIME_ENDPOINT]
   --timeout value, -t value           Timeout of connecting to the server (default: 10s)
   --help, -h                          show help
   --version, -v                       print the version

crictldocker是两个不同的命令行工具,用于管理容器运行时环境。

1. 功能区别:

  • crictl是一个与容器运行时(container runtime)通信的命令行工具,用于管理和操作底层容器运行时的功能,如创建、启动、停止、删除容器等。它主要用于与CRI(Container Runtime Interface)兼容的容器运行时交互,如Docker的标准容器运行时containerd或Kubernetes的容器运行时cri-o等。
  • docker是一个完整的容器平台,提供了更高级别的功能和抽象,包括构建镜像、创建容器、管理容器网络、存储卷等。它是一个面向开发者和运维人员的工具,可以方便地构建、部署和管理容器应用。

2. 使用场景区别:

  • crictl更适合在容器运行时层面进行操作,例如调试容器运行时问题、查看底层容器状态、手动管理容器等。它对于需要直接与容器运行时进行交互的用户或开发者较为有用。
  • docker则更适合在更高层面上使用容器技术,例如构建、发布和管理应用程序、多容器应用编排、容器集群管理等。它对于需要使用容器来进行应用开发和部署的用户或运维人员较为有用。

因此,crictldocker之间存在一定的功能和使用场景上的区别,具体取决于你的需求和使用方式。

6 docker-containerd-shim

containerd-shim 是一个开源的容器运行时组件,它是由 Docker 团队开发并维护的。它负责与 containerd 守护进程交互,并协调容器的创建、启动、停止和销毁等操作。

具体而言,containerd-shim 在容器生命周期中扮演了重要的角色,主要有以下几个功能:

  1. 创建容器:当用户请求创建一个容器时,containerd-shim 接收来自 containerd 守护进程的请求,并根据指定的配置参数创建对应的容器。

  2. 容器启动和管理:一旦容器创建完成,containerd-shim 负责启动容器,并监控其运行状态。它会与容器的命名空间进行交互,实现容器内部的文件系统、网络和进程隔离。同时,containerd-shim 还负责处理容器内的标准输入输出(stdin/stdout)和信号传递等操作。

  3. 容器停止和销毁:当用户请求停止或销毁容器时,containerd-shim 会接收相应的命令,并执行相应的操作。它会发送信号给容器内的进程,以通知它们停止运行,并清理容器相关资源。

总之,containerd-shim 充当了容器运行时与 containerd 之间的桥梁,承担了容器的创建、启动、停止和销毁等操作。它起到了连接容器与底层基础设施的作用,使得容器可以在一个安全、独立的环境中运行。

7 doccker-runc > runc

runc是一个轻量级的进程容器运行时工具,可以用于创建和运行容器。它是OCI(Open Container Initiative)标准的一部分,负责管理和执行容器中的进程。

runc的主要作用包括:

  1. 创建容器:runc可以根据给定的配置文件创建容器。这些配置文件定义了容器的各种属性,如命名空间、文件系统挂载、资源限制等。

  2. 运行容器:runc可以启动容器中定义的进程,并在容器内部创建所需的命名空间和隔离环境。它负责设置容器的运行时配置,如进程环境变量、文件系统、网络配置等。

  3. 管理容器生命周期:runc提供了管理容器生命周期的功能。它可以启动容器、监控容器的状态,并在需要时停止或销毁容器。

  4. 实现容器隔离:runc利用Linux内核的命名空间和cgroup机制,实现了容器的隔离性。每个容器都有独立的命名空间,使得容器内的进程在运行时无法感知到其他容器或宿主系统的存在。

总的来说,runc提供了一个简单而可靠的方式来管理和运行容器,为构建和使用容器化应用程序提供了基础设施。它被广泛用于各种容器管理工具和平台,如Docker、Kubernetes等。
CRI 之runc & containerd

8 docker命令

docker -h
Flag shorthand -h has been deprecated, please use --help

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.10.5)
  compose*    Docker Compose (Docker Inc., v2.18.1)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/

猜你喜欢

转载自blog.csdn.net/hezuijiudexiaobai/article/details/131691222