Skip to content

Commit b8d6927

Browse files
committed
[es] Fix address binding for Swarm Mode
1 parent 4a7ecff commit b8d6927

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

elasticsearch/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ EXPOSE 9200 9300
1515

1616
ENV ES_HOME=/usr/share/elasticsearch-$ES_VERSION \
1717
DEFAULT_ES_USER=elasticsearch \
18-
DISCOVER_TRANSPORT_IP=eth0 \
19-
DISCOVER_HTTP_IP=eth0 \
2018
ES_JAVA_OPTS="-Xms1g -Xmx1g"
2119

2220
RUN adduser -S -s /bin/sh $DEFAULT_ES_USER

elasticsearch/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,16 @@ Using the Docker Compose file above, a value of `2` is appropriate when scaling
182182

183183
docker-compose scale master=3
184184

185-
## Auto transport/http discovery with Swarm Mode
185+
## Multiple Network Binding, such as Swarm Mode
186186

187-
When using Docker Swarm mode (starting with 1.12), the overlay and ingress network interfaces are assigned
188-
multiple IP addresses. As a result, it creates confusion for the transport publish logic even when using
189-
the special value `_eth0_`.
187+
When using Docker Swarm mode the container is presented with multiple ethernet
188+
devices. By default, all global, routable IP addresses are configured for
189+
Elasticsearch to use as `network.host`.
190190

191-
To resolve this, add
191+
That discovery can be overridden by providing a specific ethernet device name
192+
to `DISCOVER_TRANSPORT_IP` and/or `DISCOVER_HTTP_IP`, such as
192193

193194
-e DISCOVER_TRANSPORT_IP=eth0
194-
195-
replacing `eth0` with another interface within the container, if needed.
196-
197-
The same can be done for publish/binding of the http module by adding:
198-
199195
-e DISCOVER_HTTP_IP=eth2
200196

201197
## Heap size and other JVM options

elasticsearch/start

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ discoverIpFromLink() {
1919
OPTS="$OPTS -E $mode.host=$ip"
2020
}
2121

22+
discoverAllGlobalIps() {
23+
ips=`ipaddr show scope global|awk '$1 == "inet" { if (!match($2,"/32")) { gsub("/.*","",$2) ; addrs[length(addrs)] = $2 } } END { for (i in addrs) { if (i>0) printf "," ; printf addrs[i] } }'`
24+
OPTS="$OPTS -E network.host=$ips"
25+
}
26+
2227
setup_clustering() {
2328

2429
if [ -n "$CLUSTER" ]; then
@@ -112,8 +117,13 @@ OPTS="$OPTS \
112117
-E transport.tcp.port=9300 \
113118
-E http.port=9200"
114119

115-
discoverIpFromLink $DISCOVER_TRANSPORT_IP transport
116-
discoverIpFromLink $DISCOVER_HTTP_IP http
120+
discoverAllGlobalIps
121+
if [ "${DISCOVER_TRANSPORT_IP}" != "" ]; then
122+
discoverIpFromLink $DISCOVER_TRANSPORT_IP transport
123+
fi
124+
if [ "${DISCOVER_HTTP_IP}" != "" ]; then
125+
discoverIpFromLink $DISCOVER_HTTP_IP http
126+
fi
117127

118128
setup_personality
119129
setup_clustering

0 commit comments

Comments
 (0)