@Test
    void hazelcastCluster() {
        try (
            Network network = Network.newNetwork();
            GenericContainer<?> container1 = new GenericContainer<>(DockerImageName.parse(HZ_IMAGE_NAME))
                .withExposedPorts(DEFAULT_EXPOSED_PORT)
                .withEnv(HZ_CLUSTERNAME_ENV_NAME, TEST_CLUSTER_NAME)
                // Flags necessary to run on Github Actions which runs on an Azure VM
                .withEnv(HZ_NETWORK_JOIN_AZURE_ENABLED_ENV_NAME, FALSE_VALUE)
                .withEnv(HZ_NETWORK_JOIN_MULTICAST_ENABLED_ENV_NAME, TRUE_VALUE)
                .waitingFor(Wait.forLogMessage(CLUSTER_STARTUP_LOG_MESSAGE_REGEX, 1))
                .withNetwork(network);
            GenericContainer<?> container2 = new GenericContainer<>(DockerImageName.parse(HZ_IMAGE_NAME))
                .withExposedPorts(DEFAULT_EXPOSED_PORT)
                .withEnv(HZ_CLUSTERNAME_ENV_NAME, TEST_CLUSTER_NAME)
                // Flags necessary to run on Github Actions which runs on an Azure VM
                .withEnv(HZ_NETWORK_JOIN_AZURE_ENABLED_ENV_NAME, FALSE_VALUE)
                .withEnv(HZ_NETWORK_JOIN_MULTICAST_ENABLED_ENV_NAME, TRUE_VALUE)
                .waitingFor(Wait.forLogMessage(CLUSTER_STARTUP_LOG_MESSAGE_REGEX, 1))
                .withNetwork(network)
        ) {
            Startables.deepStart(container1, container2).join();
            assertThat(container1.isRunning()).isTrue();
            assertThat(container2.isRunning()).isTrue();

            ClientConfig clientConfig = new ClientConfig();
            clientConfig
                .setClusterName(TEST_CLUSTER_NAME)
                .getNetworkConfig()
                // Uncomment the next line to remove the "WARNING: ...Could not connect to member..." message
                //.setSmartRouting(false)
                .addAddress(container1.getHost() + HOST_PORT_SEPARATOR + container1.getFirstMappedPort())
                .addAddress(container2.getHost() + HOST_PORT_SEPARATOR + container2.getFirstMappedPort());

            HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

            assertThat(client.getCluster().getMembers()).hasSize(2);

            BlockingQueue<String> queue = client.getQueue(TEST_QUEUE_NAME);
            queue.put(TEST_VALUE);

            assertThat(queue.take()).isEqualTo(TEST_VALUE);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException("Interrupted during hazelcastCluster test", e);
        }
    }
Examples with Hazelcast using both a single container and a cluster with two containers.
examples/hazelcast/src/test/java/org/testcontainers/examples/HazelcastTest.java