Docker - 遠(yuǎn)程連接

docker默認(rèn)通訊方式只支持本地形式調(diào)用,不支持TCP遠(yuǎn)程,如何增加docker支持通過TCP方式管理docker,可通過配置文件形式,各個(gè)版本的方式配置不同,以下會(huì)針對某一個(gè)版本進(jìn)行演示。

使用說明

演示版本

[root@test1 docker]# docker --version
Docker version 17.06.0-ce, build 02c1d87

演示系統(tǒng)Centos7

[root@test1 docker]# uname -a
Linux test1 3.10.0-514.21.2.el7.x86_64 #1 SMP Tue Jun 20 12:24:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

簡易版本

創(chuàng)建/etc/docker/daemon.json文件

{
  "hosts": ["tcp://0.0.0.0:2376","unix:///var/run/docker.sock"]
}

復(fù)雜版本

配置

cat /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[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
ExecReload=/bin/kill -s HUP $MAINPID
# 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
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

將以上配置中的

ExecStart=/usr/bin/dockerd

修改為

ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375

通用部分

重啟docker網(wǎng)絡(luò)

systemctl daemon-reload 

重啟docker服務(wù)

systemctl restart docker

即可進(jìn)行本地或遠(yuǎn)程API調(diào)用


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容