docker学习(七)docker daemon

news/2024/5/9 23:57:30/文章来源:https://blog.csdn.net/cliffordl/article/details/131478485

1.Docker 的CS模式

1.1.Docker 的C/S模式介绍

在 Docker Client 中来运行 Docker 的各种命令,这些命令会传送给在 Docker 的宿主机上运行的 Docker 守护进程。而 Docker 守护进程是负责实现 Docker 各种功能的。
在这里插入图片描述
如图所示,Docker 守护进程运行在宿主机上,也就是“C/S架构”的Server(服务)端,守护进程启动后,一直在后台运行,负责实现 Docker 的各种功能。Docker 的使用者要通过 Docker 的客户端,与守护进程进行交互,也就是 Docker 的命令行接口,与 Docker 守护进程进行通信。这个命令行接口,也就是在 Shell 中执行 Docker 命令时运行的二进制程序,它是 Docker 最主要的用户接口,用来从用户处接收 Docker 的命令,并且传递给守护进程;而守护进程将命令执行的结果返回给客户端,返显示在命令行接口中。

1.2.Docker 客户端与守护进程的通信方式

Docker 客户端与守护进程,实际上是通过 Socket 进行连接的。
Docker 提供了三种 Socket 连接的模式:

  • Unix 的端口模式
    unix:///var/run/docker.sock
  • TCP 协议的 host:port 模式
    tcp://host:port
  • fd 的 Socket 模式
    fd://socketfd

其中,Unix 的端口模式是 Docker 默认的客户端与守护进程的连接方式。我们也可以通过配置进行修改,来修改 Socket 连接方式。
在这里插入图片描述
用户可以通过命令行接口,或者自定义的应用,来与客户端进行连接。这个客户端可以是 Docker 提供的二进制程序( Shell 中运行的 Docker 命令),也可以是用户自定义的程序,而这个程序是通过调用Remote API来调用Docker的服务。而 Docker 客户端与 Docker 服务端是通过 Socket 进行连接,这种连接本身也就意味着,Docker 客户端与服务端既可以在同一台机器,也可以在不同机器上运行。也就是 Docker 客户端可以通过远程访问的方式,来访问 Docker 服务端。

2.Docker 守护进程的配置

2.1.Docker 守护进程的启停

启动、停止和重启 Docker 守护进程,需要使用到Linux的service命令,相关的操作如下:

sudo service docker start
sudo service docker stop
sudo service docker restart
# 等同于
sudo systemctl start docker
sudo systemctl stop docker
sudo systemctl restart docker

当修改了 Docker 启动配置时,就需要使用 service 命令来重新启动 Docker 服务,以使得修改的配置能够得到应用。

2.2.Docker 的启动选项

Docker 针对不同的应用场景,为守护进程提供了非常丰富的启动配置选项。而这种配置选项,是通过如下格式来运行的:

docker -d [OPTIONS]

其中 -d 是代表以“守护”的方式来运行Docker的程序,后面的“[OPTIONS]”就是守护进程的配置选项,Docker提供了非常丰富的配置选项,如下:
Docker守护进程相关:
与 Docker 守护进程相关的运行选项,它包含了 Docker 的目录、日志级别、进程id、写入文件的地址、debug 模式的开启以及 docker 运行时使用的驱动模式等等:

	-D, --debug=false:debug模式的开启-e, --exec-driver="native":docker运行时使用的驱动模式-g, --graph="/var/lib/docker":设置Docker运行时根目录--icc=true:设置启用内联容器的通信。-l,--log-level="info":docker的日志级别指定--label=[]:docker标签-p, --pidfile="/var/run/docker.pid":设置后台进程PID文件路径。

Docker服务器连接相关:

	-G, --group="docker":在后台运行模式下,赋予指定的Group到相应的unix socket上。注意,当此参数 --group 赋予空字符串时,将去除组信息-H, --host=[]:设置后台模式下指定socket绑定,可以绑定一个或多个 tcp://host:port, unix:///path/to/socket, fd://* 或 fd://socketfd。如:$ docker -H tcp://0.0.0.0:2375 ps 或者$ export DOCKER_HOST="tcp://0.0.0.0:2375"$ docker ps--tls=false:设置是否使用TLS--tlscacert="/home/sven/.docker/ca.pem":设置要在远程证书中使用的CA证书文件的路径--tlscert="/home/sven/.docker/cert.pem":设置证书文件路径--tlskey="/home/sven/.docker/key.pem":设置密匙文件路径--tlsverify=false:使用TLS远程证书,守护进程与客户端全部使用证书验证

Remote API相关:

	--api-enable-cors=false:设置是否允许远程API调用。

存储相关:

	-s, --storage-driver="":设置容器运行时使用指定的存储驱动,如,指定使用devicemapper,可以这样:docker -d -s devicemapper--selinux-enabled=false:设置启用selinux支持--storage-opt=[]:设置存储驱动的参数

Registry(仓库连接)相关:

	--insecure-registry=[]:使用私有证书搭建docker注册服务器时,设置docker注册服务器域名--registry-mirror=[]:设置docker registry 的镜像地址

网络设置相关:

	-b, --bridge="":使用事先创建的网桥接口。若设置为none,则不在容器内使用网络--bip="":使用CIDR标记法设置docker 的IP带宽。该选项不能与-b选项同时使用--fixed-cidr="":固定分配IPv4地址的带宽。该IP地址必须在-b选项设置的网桥网络或--bip设置的IP网段内--fixed-cidr-v6="":设置 IPv6子网--dns=[]:设置容器使用DNS服务器。例如: docker -d --dns 8.8.8.8--dns-search=[]:设置容器使用指定的DNS搜索域名。如: docker -d --dns-search example.com--ip=0.0.0.0:设置容器绑定IP时使用的默认IP地址--ip-forward=true:设置启动容器的 net.ipv4.ip_forward--ip-masq=true:为网桥上的IP地址开启IP伪装(masquerading)--iptables=true:设置启动Docker容器自定义的iptable规则--ipv6=false:设置是否使用ipv6子网--mtu=0:设置容器网络的MTU值,如果没有这个参数,选用默认 route MTU,如果没有默认route,就设置成常量值 1500

Docker官方网站:​https://docs.docker.com/reference/commandline/cli​

2.3.Docker 服务配置

Docker的启动配置文件:

  • 老版:
    在1.12版本后之前,由于不同操作系统不同的init初始化系统,Docker的初始化配置文件根据不同的系统放置在不同的位置,在Ubuntu 中的位置是:/etc/default/docker,在CentOS中的位置是:/etc/sysconfig/docker。
    “tcp”协议配置老版端口默认是2375
  • 新版:
    1.12版本后,用户可以自行创建 /etc/docker/daemon.json,该文件是 docker 进程的配置管理文件,里面几乎包含了所有 docker 命令行启动可以配置的参数,不管是哪个平台,不管是以何种方式启动,默认都会来这里读取配置。
    “tcp”协议配置新版端口默认是5678

为本地 Docker 服务添加一个“ labels 选项”:

[test@localhost ~]# sudo vim /etc/docker/daemon.json
# {} 不能有多个
{"labels" : ["nodeName=docker_server_1"]
}

“ labels 选项”可以定义一个key-value的值,而这个值可以在“docker info”命令中查看到。

# 重启docker
[test@localhost ~]$ sudo service docker restart
# 查看labels信息,nodeName=docker_server_1已添加
[test@localhost ~]$ sudo docker info 
Client:Context:    defaultDebug Mode: falsePlugins:app: Docker App (Docker Inc., v0.9.1-beta3)buildx: Build with BuildKit (Docker Inc., v0.4.2-docker)Server:Containers: 5Running: 0Paused: 0Stopped: 5Images: 26Server Version: 20.10.0Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38runc version: v1.1.5-0-gf19387ainit version: de40ad0Security Options:seccompProfile: defaultKernel Version: 3.10.0-1160.83.1.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 112Total Memory: 125.4GiBName: localhost.localdomainID: BQJU:EZOH:U5ZS:YI3X:EDS3:WA2Z:XB4C:3KPF:ZAXF:2ZFM:ZZLR:4LJEDocker Root Dir: /var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/# Labels信息已添加Labels:nodeName=docker_server_1Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: false[test@localhost ~]$

3.Docker 的远程访问

3.1.Docker 远程访问概述

远程访问的时候,需要保证两台服务器的API版本一致,通过“docker version”版本信息查看指令。
默认情况下,Docker的守护进程使用的是“unix”模式来实现与客户端的通信。这里需要用“tcp”模式来进行网络交互。有两种方式配置:
首先,在 docker daemon 配置文件 /lib/systemd/system/docker.service 中的“ExecStart”选项后,添加“tcp”协议的配置。

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:5678

其次,是在/etc/docker/daemon.json文件中配置,需要修改 /lib/systemd/system/docker.service,去掉所有-H 参数:

[test@localhost ~]# sudo vim /etc/docker/daemon.json
{"hosts": ["tcp://0.0.0.0:5678", "unix:///var/run/docker.sock"]
}

Ps:目前笔者使用的 Docker 20.10.0-ce版本。

3.2.修改docker.service方式

查看 docker socket 模式:

# ps查看看不到“-H tcp://0.0.0.0:5678”信息
[test@localhost ~]$ ps -ef | grep docker 
root       7616      1  0 17:43 ?        00:00:01 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
# 使用curl链接,会被拒绝
[test@localhost ~]$ curl http://127.0.0.1:5678/info
curl: (7) Failed connect to 127.0.0.1:5678; 拒绝连接
[test@localhost ~]$ 

修改 /lib/systemd/system/docker.service 配置,添加ExecStart项:

[test@localhost ~]# sudo vim /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service multi-user.target
Wants=network-online.target
Requires=docker.socket containerd.service[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# 默认版本
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
# 添加 -H tcp://0.0.0.0:5678
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:5678
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500[Install]

添加完tcp之后,重启:

sudo systemctl daemon-reload
sudo service docker restart

再次查看 docker socket 模式,“tcp”已添加,并本机测试“tcp”:

[test@localhost ~]$ ps -ef | grep docker 
root      45102      1  3 17:54 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:5678
[test@localhost ~]$ curl http://127.0.0.1:5678/info
{"ID":"BQJU:EZOH:U5ZS:YI3X:EDS3:WA2Z:XB4C:3KPF:ZAXF:2ZFM:ZZLR:4LJE","Containers":5,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":5,"Images":26,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","xfs"],["Supports d_type","true"],["Native Overlay Diff","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","local","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"KernelMemoryTCP":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":23,"OomKillDisable":true,"NGoroutines":34,"SystemTime":"2023-06-30T17:58:32.0594699+08:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","CgroupVersion":"1","NEventsListener":0,"KernelVersion":"3.10.0-1160.83.1.el7.x86_64","OperatingSystem":"CentOS Linux 7 (Core)","OSVersion":"7","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":112,"MemTotal":134651682816,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"localhost.localdomain","Labels":["nodeName=docker_server_1"],"ExperimentalBuild":false,"ServerVersion":"20.10.0","Runtimes":{"io.containerd.runc.v2":{"path":"runc"},"io.containerd.runtime.v1.linux":{"path":"runc"},"runc":{"path":"runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"2806fc1057397dbaeefbea0e4e17bddfbd388f38","Expected":"2806fc1057397dbaeefbea0e4e17bddfbd388f38"},"RuncCommit":{"ID":"v1.1.5-0-gf19387a","Expected":"v1.1.5-0-gf19387a"},"InitCommit":{"ID":"de40ad0","Expected":"de40ad0"},"SecurityOptions":["name=seccomp,profile=default"],"Warnings":["WARNING: API is accessible on http://0.0.0.0:5678 without encryption.\n         Access to the remote API is equivalent to root access on the host. Refer\n         to the 'Docker daemon attack surface' section in the documentation for\n         more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface"]}
[test@localhost ~]$

异地(10.49.44.16)测试"tcp"(docker daemon 主机IP为:10.49.44.14):

[test@localhost ~]$ curl http://10.49.44.14:5678/info
{"ID":"BQJU:EZOH:U5ZS:YI3X:EDS3:WA2Z:XB4C:3KPF:ZAXF:2ZFM:ZZLR:4LJE","Containers":5,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":5,"Images":26,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","xfs"],["Supports d_type","true"],["Native Overlay Diff","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","local","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"KernelMemoryTCP":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":23,"OomKillDisable":true,"NGoroutines":34,"SystemTime":"2023-07-03T09:31:56.804561345+08:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","CgroupVersion":"1","NEventsListener":0,"KernelVersion":"3.10.0-1160.83.1.el7.x86_64","OperatingSystem":"CentOS Linux 7 (Core)","OSVersion":"7","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":112,"MemTotal":134651682816,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"localhost.localdomain","Labels":["nodeName=docker_server_1"],"ExperimentalBuild":false,"ServerVersion":"20.10.0","Runtimes":{"io.containerd.runc.v2":{"path":"runc"},"io.containerd.runtime.v1.linux":{"path":"runc"},"runc":{"path":"runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"2806fc1057397dbaeefbea0e4e17bddfbd388f38","Expected":"2806fc1057397dbaeefbea0e4e17bddfbd388f38"},"RuncCommit":{"ID":"v1.1.5-0-gf19387a","Expected":"v1.1.5-0-gf19387a"},"InitCommit":{"ID":"de40ad0","Expected":"de40ad0"},"SecurityOptions":["name=seccomp,profile=default"],"Warnings":["WARNING: API is accessible on http://0.0.0.0:5678 without encryption.\n         Access to the remote API is equivalent to root access on the host. Refer\n         to the 'Docker daemon attack surface' section in the documentation for\n         more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface"]}
[test@localhost ~]$ 

发现都是可以连通的。
此时我们可以尝试在 Docker 的查询指令中间添加“-H tcp://10.49.44.14:5678”来运行远程Docker指令:

[test@localhost ~]$ sudo docker -H tcp://10.49.44.14:5678 info
Client:Context:    defaultDebug Mode: falseServer:Containers: 5Running: 0Paused: 0Stopped: 5Images: 26Server Version: 20.10.0Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38runc version: v1.1.5-0-gf19387ainit version: de40ad0Security Options:seccompProfile: defaultKernel Version: 3.10.0-1160.83.1.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 112Total Memory: 125.4GiBName: localhost.localdomainID: BQJU:EZOH:U5ZS:YI3X:EDS3:WA2Z:XB4C:3KPF:ZAXF:2ZFM:ZZLR:4LJEDocker Root Dir: /var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:nodeName=docker_server_1Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: falseWARNING: API is accessible on http://0.0.0.0:5678 without encryption.Access to the remote API is equivalent to root access on the host. Referto the 'Docker daemon attack surface' section in the documentation formore information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
test@10.49.44.16:~$ 

这是因为此时在执行 Docker 命令时,会连接到 -H 指定的远程 Docker 服务器上。

3.3.修改daemon.json方式

修改 /lib/systemd/system/docker.service 配置ExecStart项,去掉所有-H 项,不然会与daemon.json产生冲突:

[test@localhost ~]$ sudo vim /lib/systemd/system/docker.service
......
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
# 添加 -H tcp 参数
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:5678
# 不添加 -H 参数
ExecStart=/usr/bin/dockerd
......

重启:

sudo systemctl daemon-reload
sudo service docker restart

查看 docker socket 模式:

# ps查看看不到“-H tcp://0.0.0.0:5678”信息
[test@localhost ~]$ ps -ef | grep docker 
root       7616      1  0 17:43 ?        00:00:01 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
# 使用curl链接,会被拒绝
[test@localhost ~]$ curl http://127.0.0.1:5678/info
curl: (7) Failed connect to 127.0.0.1:5678; 拒绝连接
[test@localhost ~]$ 

修改/etc/docker/daemon.json配置文件,添加hosts参数,然后重启服务:

[test@localhost ~]$ vim /etc/docker/daemon.json
{"labels" : ["nodeName=docker_server_1"],"hosts": ["tcp://0.0.0.0:5678", "unix:///var/run/docker.sock"],"dns" : ["114.114.114.114","8.8.8.8"]
},

ps -ef | grep docker看不到-H 信息,但是curl可以,异地也可以。

[test@localhost ~]$ ps -ef | grep docker
root      45289      1  4 10:24 ?        00:00:00 /usr/bin/dockerd
[test@localhost ~]$ curl http://127.0.0.1:5678/info
{"ID":"BQJU:EZOH:U5ZS:YI3X:EDS3:WA2Z:XB4C:3KPF:ZAXF:2ZFM:ZZLR:4LJE","Containers":6,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":6,"Images":26,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","xfs"],["Supports d_type","true"],["Native Overlay Diff","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","local","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"KernelMemoryTCP":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":24,"OomKillDisable":true,"NGoroutines":35,"SystemTime":"2023-07-03T10:25:10.152686291+08:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","CgroupVersion":"1","NEventsListener":0,"KernelVersion":"3.10.0-1160.83.1.el7.x86_64","OperatingSystem":"CentOS Linux 7 (Core)","OSVersion":"7","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":112,"MemTotal":134651682816,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"localhost.localdomain","Labels":["nodeName=docker_server_1"],"ExperimentalBuild":false,"ServerVersion":"20.10.0","Runtimes":{"io.containerd.runc.v2":{"path":"runc"},"io.containerd.runtime.v1.linux":{"path":"runc"},"runc":{"path":"runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"2806fc1057397dbaeefbea0e4e17bddfbd388f38","Expected":"2806fc1057397dbaeefbea0e4e17bddfbd388f38"},"RuncCommit":{"ID":"v1.1.5-0-gf19387a","Expected":"v1.1.5-0-gf19387a"},"InitCommit":{"ID":"de40ad0","Expected":"de40ad0"},"SecurityOptions":["name=seccomp,profile=default"],"Warnings":["WARNING: API is accessible on http://0.0.0.0:5678 without encryption.\n         Access to the remote API is equivalent to root access on the host. Refer\n         to the 'Docker daemon attack surface' section in the documentation for\n         more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface"]}
[test@localhost ~]$

/lib/systemd/system/docker.service -H 与/etc/docker/daemon.json hosts[“”]不能同时配置,不然重启失败:

[test@localhost ~]$ sudo systemctl daemon-reload
[test@localhost ~]$ sudo service docker restart
Redirecting to /bin/systemctl restart docker.service
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[test@localhost ~]$

3.4.docker -H方式

[test@localhost ~]$ sudo dockerd --debug   --tls=true   --tlscert=/var/docker/server.pem   --tlskey=/var/docker/serverkey.pem   --host tcp://127.0.0.1:5678
INFO[2023-07-03T10:50:36.985386294+08:00] Starting up                                  
failed to create API server: Could not load X509 key pair (cert: "/var/docker/server.pem", key: "/var/docker/serverkey.pem"): open /var/docker/server.pem: no such file or directory
[test@localhost ~]$ 

提示证书不存在。已经有3.2.和3.3两种方式了,这种方式以后在研究吧。
参考:https://blog.csdn.net/a1010256340/article/details/80106735

3.5.Docker 环境变量配置

如果我们需要频繁访问远程 Docker 指令,一直添加“-H”指令明显很繁琐,所以 Docker 客户端提供了一个环境变量来简化该操作。
首先我们使用 export 指令来设置环境变量:export DOCKER_HOST=“tcp://127.0.0.1:5678”。
设置完毕之后,我们运行 sudo docker info 命令,返回的信息也是远程服务器的。
如果我们使用完了远程的服务器,需要连接本机时,只需使用exoprt指令将“DOCKER_HOST”环境变量置空,即可恢复本机的Docker服务连接。此时我们再运行 info 命令,显示的就是我们本机的Docker信息了。

4.Docker 常用接口

curl http://10.49.44.14:5678/info // 相当于在本地 docker info访问
curl http://10.49.44.14:5678/containers/json // 返回活动的容器
curl http://10.49.44.14:5678/containers/json?all=1 // 返回所有容器
curl http://10.49.44.14:5678/images/json
在linux下,可以通过curl工具访问url,因为返回的是json串,非格式化的。可以结合python命令,转为格式化的json,让看起来比较清。如:
curl http://10.49.44.14:5678/images/json | python -mjson.tool

参考:
https://
blog.51cto.com/u_16012040/6130770
https://blog.51cto.com/u_16012040/6142527
https://blog.51cto.com/u_16012040/6142525
https://www.cnblogs.com/xiugeng/p/16323859.html
https://www.cnblogs.com/51kata/p/5267687.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_325658.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第四章 数组

前言 学习方法 可以多看几遍视频把上课的代码,自己加加注释,在自己写之前,可以画一个流程图照着流程图把代码自己实现一遍 不要怀疑自己,不要遇到困难就觉得自己不行,遇到困难就解决困难,编程初学者都是…

SSH连接vmware 虚拟机 centos

检查虚拟机设置的网络连接是否为NAT模式 点击左上角“编辑” -> “虚拟网络编辑器” 在虚拟网络编辑器中查看IP地址 ,点击NAT模式后,点击“NAT设置 记住自己的网关,下面在服务器中配置需要 进入服务器的 /etc/sysconfig/network-scripts/ 编辑 i…

浑元太极马老师和小薇-UMLChina建模知识竞赛第4赛季第7轮[更新]

DDD领域驱动设计批评文集 欢迎加入“软件方法建模师”群 《软件方法》各章合集 参考潘加宇在《软件方法》和UMLChina公众号文章中发表的内容作答。在本文下留言回答。 第7轮一直无人得分,再次更换题目。 因有的题目之前已经出过,本轮需要最先答对全…

Android View 事件派发流程

原文链接 Android View 事件派发流程 自从乔帮主横空出世推出了iPhone以来,触控式的操作便成了21世纪智能设备的标准输入方式。对于同是智能操作系统的Android来说,也不例外。事件,特别是触控事件对于移动应用程序开发来说是一个非常重要的&…

软件DevOps云化发展的趋势 【课程限时免费】

你了解什么是DevOps吗? 它是怎么诞生的? DevOps能做些什么? 相信对于DevOps的实践者和关注者来说,对它已经不陌生了,但是对于刚刚进入开发者领域不久的小伙伴应该并不清楚,下面就让小智带你一起了解DevO…

C. Insert Zero and Invert Prefix - 构造+思维

分析: 数组b的最后一个元素永远不可能使1,因为即使在最后一个位置操作,也只会把前n-1个元素反转,最后一个元素只能为0.然后可以发现只要a[i]0就可以直接输出0,当a[i]1时一连串的1只需要最后一个1的位置改变成1的字串长…

Keil5中写的软件延时函数不起作用现象解析_ARM_Compiler_volatile关键字

一、问题描述 在学习野火霸天虎F407寄存器点亮LED时,出现实验现象:LED灯不亮,野火霸天虎F407资料。 main.c代码如下: #include "stm32f4xx.h"void Delay(unsigned int count);int main(void) { #if 0/* 第一步&a…

oracle rowscn 简单记录

可以通过ROWSCN 侦测row是否有变化,但需要注意: 默认是一个block的scn 相同可以通过create table ROWDEPENDENCIES 在每行上记录无论哪种模式,ROW SCN是一个大致值,不是准确值 NOROWDEPENDENCIES | ROWDEPENDENCIES This claus…

Maven安装和配置详细教程

Maven安装和配置详细教程 1、Maven简介 Maven 是 Apache 软件基金会的一个开源项目,是一个优秀的项目构建工具,它用来帮助开发者管理项目中的 jar,以及 jar 之间的依赖关系、完成项目的编译、测试、打包和发布等工作。 2、Maven下载 点击Maven下载官方地址下载Maven。或者去…

C#与C++编程环境对比:优点与应用场景详解

C#与C是两种常用的编程语言,它们在编程环境方面有一些相同点和不同点。首先,它们都可以用于开发跨平台的应用程序。其次,它们都具有强大的面向对象编程能力。但是,它们在语法、性能和应用领域等方面存在一些不同点 。 在语法方面…

使用Wireshark 找出 TCP 吞吐瓶颈

Debug 网络质量的时候,我们一般会关注两个因素:延迟和吞吐量(带宽)。延迟比较好验证,Ping 一下或者 mtr[1] 一下就能看出来。这篇文章分享一个 debug 吞吐量的办法。 看重吞吐量的场景一般是所谓的长肥管道(Long Fat …

【C】数据在内存中的存储

前言 > 在内存中,整型和浮点型存储的方式是不同的,从内存中读取的方式也是有所差异的,这篇文章主要介绍整型和浮点型在内存中存储的方式。 整型在内存中的存储 计算机中有符号数有3种表示方式: 原码:直接将二进制按…

GO语言包相关总结 -引用(本地和远程),自定义,安装,使用

本篇文章总结以下go语言包相关的知识。 目录 一.导入包 (1)常规导入 (2)别名导入 (3)特殊导入 二.自定义包 三.安装自定义包 四.调用自定义包调用 五.获取远程包 六.go中的保留函数 七.实战 - G…

机器学习技术(二)——Python科学运算模块(Numpy、Pandas)

机器学习技术(二)——Python科学运算模块(Numpy、Pandas) 文章目录 机器学习技术(二)——Python科学运算模块(Numpy、Pandas)一、Numpy1、介绍、安装与导入2、Numpy常用操作 二、Pan…

mybatis多参数传递报错问题分析+硬核mybatis底层源码分析+@Param注解+图文实战环境分析【4500字详解打通,没有比这更详细的了!】

文章目录 1.问题描述2.问题场景模拟再现2.1 场景环境2.2 数据库与表创建2.3 Maven环境搭建🍀 pom.xml导入依赖🍀 jdbc.properties🍀 mybatis-config.xml🍀 User实体类🍀 Mapper 接口🍀 UserMapper.xml 映射…

IT-OT 安全融合是优化风险管理的关键

最新报告揭示了运营技术检测和响应方面的显着可见性差距。 全球网络安全运营商趋势科技宣布了一项新研究,显示企业安全运营中心 (SOC) 正在将其能力扩展到 OT 领域。 然而,重大的可见性和技能相关的挑战仍然造成障碍。 研究发现,一半的组织…

决策树ID3

文章目录 题目一基础知识解题过程①算总的信息量②求解各个指标的信息增益,以此比较得出根节点③ 从根节点下的晴天节点出发循环上述步骤④ 从根节点下的多云节点出发,循环上述步骤⑤ 从根节点下的雨节点出发,循环上述步骤⑥画出最终的决策树…

4.设计模式之后七种模式后11种模式命令访问者迭代器发布订阅中介者忘备录解释器状态策略职责链和空模式

1.命令(command)模式 不知道命令接收者(对象)是谁,支持撤销 (接受者 间接调用执行 的具体行为) 命令调用者和接收者解耦 //只要实现命令接口即可 (就是客户端给个命令,然后命令类传给接收类执行) 优点和缺点 容易撤销操作 命令队列可以多线程操作 增加过多的命令类 空命令也是一…

揭秘元宇宙背后的最炫科技风

:元宇宙,这个词汇在近年来越来越被人们所熟知。它是一个虚拟的世界,由数字化的现实世界和虚拟现实技术所构成。在元宇宙中,人们可以自由地探索、交互、创造和享受各种虚拟体验。而这一切,都离不开最炫科技风的支持。 …

道路车辆功能安全第2 部分:功能安全管理

道路车辆功能安全 第2 部分:功能安全管理 1 范围 GB/T 34590的本部分规定了应用于汽车领域的功能安全管理的要求,包括: ——独立于项目的关于所涉及组织的要求(整体安全管理);及 ——项目特定的在安全生命周…