Docker是一种C/S结构,所以就会有客户端和服务端。Docker支持很多子命令,例如我们在命令行docker然后tab键会出来很多命令
当然docker工具很多,除了 docker 命令行工具,用户也可以通过 REST API 与服务器通信
Docker daemon是服务器组件,以 Linux 后台服务的方式运行。可以通过命令:systemctl status docker.service看到
Docker daemon 运行在 Docker host 上,负责创建、运行、监控容器,构建、存储镜像。
监听地址的配置:
默认docker daemon只能监听本地host,如果远程要访问,需要打开tcp监听,如下:
1
<code>/etc/systemd/system/multi-user</code><code>.target.wants</code><code>/docker</code><code>.service</code>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<code>[Unit]</code>
<code>Description=Docker Application Container Engine</code>
<code>Documentation=https:</code><code>//docs</code><code>.docker.com</code>
<code>After=network.target docker.socket firewalld.service</code>
<code>Requires=docker.socket</code>
<code>[Service]</code>
<code>Type=notify</code>
<code># the default is not to use systemd for cgroups because the delegate issues still</code>
<code># exists and systemd currently does not support the cgroup feature set required</code>
<code># for containers run by docker</code>
<code>ExecStart=</code><code>/usr/bin/dockerd</code> <code>-H fd:</code><code>//</code>
<code>#上面这里如果改成这样就开启了监听远程所有端口:ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0</code>
<code>ExecReload=</code><code>/bin/kill</code> <code>-s HUP $MAINPID</code>
<code>LimitNOFILE=1048576</code>
<code># Having non-zero Limit*s causes performance problems due to accounting overhead</code>
<code># in the kernel. We recommend using cgroups to do container-local accounting.</code>
<code>LimitNPROC=infinity</code>
<code>LimitCORE=infinity</code>
<code># Uncomment TasksMax if your systemd version supports it.</code>
<code># Only systemd 226 and above support this version.</code>
<code>TasksMax=infinity</code>
<code>TimeoutStartSec=0</code>
<code># set delegate yes so that systemd does not reset the cgroups of docker containers</code>
<code>Delegate=</code><code>yes</code>
<code># kill only the docker process, not all processes in the cgroup</code>
<code>KillMode=process</code>
<code>[Install]</code>
<code>WantedBy=multi-user.target</code>
重启服务端docker
<code>systemctl daemon-reload </code>
<code>systemctl restart docker.service</code>
调试
可以通过在客户端通过H参数来指定服务器和info子命令来查看服务端信息
这里可以看到哦啊服务端运行情况
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<code>root@d1:</code><code>/etc/apt</code><code># docker -H 192.168.56.132 info</code>
<code>Containers: 1</code>
<code> </code><code>Running: 0</code>
<code> </code><code>Paused: 0</code>
<code> </code><code>Stopped: 1</code>
<code>Images: 1</code>
<code>Server Version: 17.03.1-ce</code>
<code>Storage Driver: aufs</code>
<code> </code><code>Root Dir: </code><code>/var/lib/docker/aufs</code>
<code> </code><code>Backing Filesystem: extfs</code>
<code> </code><code>Dirs: 9</code>
<code> </code><code>Dirperm1 Supported: </code><code>true</code>
<code>Logging Driver: json-</code><code>file</code>
<code>Cgroup Driver: cgroupfs</code>
<code>Plugins: </code>
<code> </code><code>Volume: </code><code>local</code>
<code> </code><code>Network: bridge host macvlan null overlay</code>
<code>Swarm: inactive</code>
<code>Runtimes: runc</code>
<code>Default Runtime: runc</code>
<code>Init Binary: docker-init</code>
<code>containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc</code>
<code>runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe</code>
<code>init version: 949e6fa</code>
<code>Security Options:</code>
<code> </code><code>apparmor</code>
<code> </code><code>seccomp</code>
<code> </code><code>Profile: default</code>
<code>Kernel Version: 4.4.0-31-generic</code>
<code>Operating System: Ubuntu 16.04.1 LTS</code>
<code>OSType: linux</code>
<code>Architecture: x86_64</code>
<code>CPUs: 2</code>
<code>Total Memory: 3.842 GiB</code>
<code>Name: d1</code>
<code>ID: SQ7Y:TBJA:LS5G:IQNB:CIHC:6T2D:J22X:F3QK:7AS2:7KLN:NIIQ:JLXY</code>
<code>Docker Root Dir: </code><code>/var/lib/docker</code>
<code>Debug Mode (client): </code><code>false</code>
<code>Debug Mode (server): </code><code>false</code>
<code>Registry: https:</code><code>//index</code><code>.docker.io</code><code>/v1/</code>
<code>WARNING: No swap limit support</code>
<code>Experimental: </code><code>false</code>
<code>Insecure Registries:</code>
<code> </code><code>127.0.0.0</code><code>/8</code>
<code>Registry Mirrors:</code>
<code> </code><code>http:</code><code>//febb9aec</code><code>.m.daocloud.io</code>
<code>Live Restore Enabled: </code><code>false</code>
<code></code>
本文转自 kesungang 51CTO博客,原文链接:http://blog.51cto.com/sgk2011/1923361,如需转载请自行联系原作者