为了账号安全,请及时绑定邮箱和手机立即绑定

Docker TCP远程连接

标签:
Docker

docker默认通讯方式只支持本地形式调用,不支持TCP远程,如何增加docker支持通过TCP方式管理docker,可通过配置文件形式,各个版本的方式配置不同,以下会针对某一个版本进行演示。

使用说明

演示版本

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

演示系统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
简易版本

创建/etc/docker/daemon.json文件

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

配置

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网络

systemctl daemon-reload 

重启docker服务

systemctl restart docker

即可进行本地或远程API调用

点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消