Search code examples
dockerhazelcast

How to run Hazelcast 3.11 with a group (cluster) name from Docker?


How do I run Hazelcast 3.11 version with a group name? In later versions there's an environment variable for that HZ_CLUSTERNAME but in 3.11 I can't find anything like it in documentation. This is how I'm trying to launch Hazelcast

docker run \
    -itd \
    --network hazelcast-network \
    --rm \
    -e HZ_CLUSTERNAME=default_groupname \
    -p 5701:5701 hazelcast/hazelcast:3.11.4

Also I tried to launch it like this

docker run \
    -itd \
    --network hazelcast-network \
    --rm \
    -v "$(pwd)"/hazelcastconf/:/mnt \
    -p 5701:5701 hazelcast/hazelcast:3.11.4 \
    java -Dhazelcast.config=/mnt/hazelcast.xml

with config as follows

<hazelcast xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-3.11.xsd">
    <group>
        <name>default_groupname</name>
    </group>
    <network>
        <port auto-increment="true" port-count="100">5701</port>
        <join>
            <multicast enabled="false"></multicast>
        </join>
    </network>
    <map name="sessions">
        <time-to-live-seconds>1000</time-to-live-seconds>
    </map>
</hazelcast>

Is there a way to properly set group name while launching it in Docker?


Solution

  • The configuration overriding was added in Hazelcast 4.1 (according to the Release Notes). Details on its usage are in the Reference Manual.

    I suggest upgrading your Hazelcast version. If you don't want to upgrade or can't there is still a way to proceed with the problem in Hazelcast 3.11.z

    The way to go is mapping a custom configuration file as the volume into the container as you've guessed.

    One possible solution is to map the config file directly into the Hazelcast installation directory ("/opt/hazelcast").

    docker run ... \
     -v "$(pwd)/hazelcastconf/hazelcast.xml:/opt/hazelcast/hazelcast.xml" \
     hazelcast/hazelcast:3.11.4
    

    Or you can define the custom path in the JAVA_OPTS environment variable:

    docker run ... \
     -v "$(pwd)/hazelcastconf:/mnt" \
     -e JAVA_OPTS=-Dhazelcast.config=/mnt/hazelcast.xml \
     hazelcast/hazelcast:3.11.4
    

    The start command (CMD) in the Docker image changed over time and it's better to not touch it. ;)