In this blog we’ll talk about network considerations when using Docker with an Elasticsearch cluster.
There are different ways to setup networking in Docker and by default three network types are presented. We can list all of them using the following command:
$ docker network ls //列出docker中网络类型
none network: 完全禁止网络
host network:使用主机网络
bridge network: 桥接网络,docker默认网络
$docker network inspect bridge //查看bridge网络详情,网桥名字为docker0
docker默认只支持IPv4,如果想使用IPv6,启动docker容器时使用参数--ipv6;
当新增docker容器时,容器中创建新虚拟网络设备,为该虚拟设备分配ip,且此虚拟网络设备连接到docker0网桥。网桥在网络接口之间自动转发数据包。默认容器通过docker0连接外部设备,但外部设备却无法连接到容器。
容器实现外部设备可访问
network.publish_host配置 发布一个IP地址,使外设备可访问;
discovery.zen.ping.unicast.hosts和discovery.zen.minimum_master_nodes配置实现节点之间发现
实例:
$ docker run -d -p 9200:9200 -p 9300:9300 elasticsearch:2 \ elasticsearch \ -Des.discovery.zen.ping.unicast.hosts=192.168.99.100,192.168.99.101 \ -Des.discovery.zen.minimum_master_nodes=2 \ -Des.network.publish_host=192.168.99.100