天天看点

docker配置远程连接

在centos7上配置docker daemon的远程访问

查看帮助文档可以看到docker支持三种方式的通信,unix,tcp,fd

-H, –host=[unix:///var/run/docker.sock]: tcp://[host]:[port][path] to bind or unix://[/path/to/socket] to use.

The socket(s) to bind to in daemon mode specified using one or more

tcp://host:port/path, unix:///path/to/socket, fd://* or fd://socketfd.

If the tcp port is not specified, then it will default to either 2375 when

–tls is off, or 2376 when –tls is on, or –tlsverify is specified.

daemon指令来操作docker的守护进程,用-H 指令决定监听的对象,可同时监听多个,例如:

dockerd -H unix:///var/run/docker.sock -H tcp://192.168.59.106 -H tcp://10.10.10.2

也可以修改配置文件

在/etc/docker/daemon.json 中加入键值对

{
        "hosts":["192.168.199.106","unix:///var/run/docker.sock"]
}
           

重启docker

systemctl restart docker

此时可以通过远端client操作docker

docker -H 192.168.199.106 info

注意docker此处可能有漏洞,Docker本身提供了加密的远程管理端口2376,配合CA证书,就能提供TLS连接了。

配置docker安全可以参考 http://www.sohu.com/a/76802346_355135