Hazelcast in multinode docker environments with TCPIP

孤者浪人 提交于 2019-11-30 09:43:44

This thread and the answer from Nick Scavelli is what I think you are looking for.

https://groups.google.com/forum/#!msg/vertx/MvKcz_aTaWM/QM6CfllX9HQJ

This thread provides an answer and an example: https://groups.google.com/d/msg/orient-database/ehfKcInWZXs/wxs8xLUOGB8J

Basically you use hazelcast variables in your hazelcast file, i.e.

<property name="hazelcast.local.localAddress">${hazelcast.ip}</property>

Then when you're running the docker contained you add:

-e IP=`ip route | awk '/default/ { print  $9 }'`

Which sets an environment variable in the docker container. Then in there you do something like this:

CMD ["java", "-Dhazelcast.ip=${IP}", ...

So it's taking the docker env variable, and smashing into java as a definition, which hazelcast then picks out and substitutes into it's config file at runtime.

I want to make @gremwell's answer up-to-date, because now it's not quite correct. Property hazelcast.local.localAddress is no longer valid. Instead one should put this snippet inside hazelcast.xml

   <network>
        <public-address>${hazelcast.ip}:${hazelcast.port}</public-address>
        <port auto-increment="false" port-count="100">${hazelcast.port}</port>
        ...
   </network>

Then pass the params while starting docker container (I use official hazelcast image and mount folder with my config using -v flag)

sudo docker run -p 5701:5701 -e JAVA_OPTS="-Dhazelcast.config=/etc/conf/hazelcast.xml -Dhazelcast.ip=`ip route get 8.8.8.8 | awk '{print $NF; exit}'` -Dhazelcast.port=5701" -v /data/docker/hazelcast:/etc/conf -ti hazelcast/hazelcast

Command -Dhazelcast.ip=ip route get 8.8.8.8 | awk '{print $NF; exit}' takes host machine ip and pass it inside config file as hazelcast.ip variable. Inner port and docker port mapping should be similar 5701 in 3 places. Next container run with 5702 and so on.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!