Hazelcast and Docker container

443 views
Skip to first unread message

o haya

unread,
Mar 10, 2022, 4:24:19 PM3/10/22
to Hazelcast
Hi,

Per earlier threads, we have been using Hazelcast caching (and most recently with TCP clustering) with some of our Springboot apps.

We are looking to using Docker containers, and so we are working on running one of our existing Springboot apps, which currently uses Hazelcast for caching (and in some cases, clustering) in a Docker container, and I have some questions:

When being used/integrated with an app, does Hazelcast run as a separate process?  

The reason for this question is that (remember we are new to Docker) we have the impression that it is recommended to run only a single process in a Docker container, and I have done "ps" on the machine where our app is running and I see the app process, but I haven't been able to identify a separate process for Hazelcast?

Additionally, from searching, I saw that there is a Docker image for Hazelcast, and was wondering if we use that, is our app code need to be changed (FYI, we use programmatic configuration for Hazelcast currently) when our app is in a Docker container?

Please advise.

Thanks,
Jim

Neil Stevenson

unread,
Mar 10, 2022, 5:23:30 PM3/10/22
to haze...@googlegroups.com

 Hazelcast isn't strictly a process in itself, rather it is a collection of threads that run in a JVM process.

 If you download Hazelcast and use the "start.sh" script, it starts a process that only contains Hazelcast
 If you download the Docker image, https://hub.docker.com/r/hazelcast/hazelcast, it's the same idea, one JVM process containing one Hazelcast
 If you use Spring Boot and you have a HazelcastInstance @Bean, Spring Boot will start this bean and stop the bean as part of the JVM lifecycle.

 In all cases you can add other code and other threads to the JVM, so it'll contain Hazelcast and something else.
 You can even run two or more Hazelcasts in the one JVM process, useful sometimes for testing.

 As a Spring Boot user, you will probably find it easier to let Spring Boot launch your application and Hazelcast -- this would be my personal
recommendation but it's more a matter of choice/preference than any compelling need.

 If you are new to Docker, you will no doubt have a view of Kubernetes as next, and this brings us to configuration.
 
 For code configuration, I (personally) use a @Bean of type "com.hazelcast.config.Config", and in this bean,
check the Spring environment to determine if running in Kubernetes and to use the Kubernetes discovery,
or not and to use the TCP discovery.
 
 TCP discovery works whether you are in Docker or not, but one item that everyone trips on with Docker is networking. Inside the Docker container the process will see
one IP address but from the outside of the container it may differ. Check the system property "hazelcast.local.publicAddress"
which enables a form of NATting.

 There is a guide here https://docs.hazelcast.com/hazelcast/5.0/getting-started/get-started-docker that miight help you get started.
 
 
 Neil


















--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/2d1554a2-e038-4493-9ea9-6ba0581b8b6bn%40googlegroups.com.

This message contains confidential information and is intended only for the individuals named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required, please request a hard-copy version. -Hazelcast

Neil Stevenson

unread,
Mar 10, 2022, 5:29:15 PM3/10/22
to haze...@googlegroups.com

o haya

unread,
Apr 14, 2022, 7:24:42 AM4/14/22
to Hazelcast
Hi,

This is a followup to the information earlier above:

- We have a Springboot application that uses Hazelcast clustering and configures Hazelcat clustering programmatically, and when we build the application in Eclipse
- We want to make a DockerFile that includes both our Springboot application and Hazelcast
- We do not currently use Kubernetes or Kafka (I mention this because some of the examples in docs use Kubernetes or Kafka)

I am trying to determine the approach for doing this, and, in the document https://hub.docker.com/r/hazelcast/hazelcast, there is the "Extending Hazelcast Base Image" section, and in that section, there is this example DockerFile:

FROM hazelcast/hazelcast:$HAZELCAST_VERSION

# Adding custom hazelcast.yaml
ADD hazelcast.yaml ${HZ_HOME}
ENV JAVA_OPTS -Dhazelcast.config=${HZ_HOME}/hazelcast.yaml

 # Adding custom JARs to the classpath
ADD custom-library.jar ${HZ_HOME}

Since we are using programmatic configuration for Hazelcast, if we use the above DockerFile, but without the hazelcast.yml line, i.e.:

FROM hazelcast/hazelcast:$HAZELCAST_VERSION

 # Adding custom JARs to the classpath
ADD our-springboot-app.jar ${HZ_HOME}

would that be sufficient, and could we use that DockerFile to to create our own Docker image, that we could then "run"?

Thanks,
Jim

Neil Stevenson

unread,
Apr 14, 2022, 2:19:18 PM4/14/22
to haze...@googlegroups.com
Here's an example

This pom uses `spring-boot-maven-plugin` to form a single bundled jar, then `dockerfile-maven-plugin` to build a docker image that executes that jar

This is the Dockerfile, which copies the output of the maven compile into the docker image and executes it

Does that help?


o haya

unread,
Apr 15, 2022, 2:56:14 PM4/15/22
to Hazelcast
Yes, definitely helpful! 

Thanks, and have a great weekend!

Jim
Reply all
Reply to author
Forward
0 new messages